public void UpdateScroll() { int cursorPixelPos = ControlRenderer.GetCharPosTextField( this.rect, this.text, ControlRenderer.DefaultFont, TextBoxStyle.Sunken, this.cursorIndex, this.scroll); if (cursorPixelPos - this.rect.X < 15 && this.scroll > 0) { this.scroll = Math.Max(this.scroll - (15 - cursorPixelPos + this.rect.X), 0); this.EmitInvalidate(); } else if (cursorPixelPos - this.rect.X > this.rect.Width - 15) { this.scroll += (cursorPixelPos - this.rect.X) - (this.rect.Width - 15); this.EmitInvalidate(); } }