protected override void OnLayout(LayoutEventArgs levent) { base.OnLayout(levent); int bordersize = (!BorderColor.IsFullyTransparent()) ? 3 : 0; int textboxclienth = ClientRectangle.Height - bordersize * 2; // border is within Client area int linesinbox = EstimateLinesInBox(textboxclienth); int firstVisibleLine = unchecked ((int)(long)TextBox.SendMessage(EM.GETFIRSTVISIBLELINE, IntPtr.Zero, IntPtr.Zero)); ScrollBar.SetValueMaximumLargeChange(firstVisibleLine, LineCount - 1, linesinbox); visibleonlayout = ScrollBar.IsScrollBarOn || DesignMode || !HideScrollBar; // Hide must be on, or in design mode, or scroll bar is on due to values TextBox.Location = new Point(bordersize, bordersize); TextBox.Size = new Size(ClientRectangle.Width - (visibleonlayout ? ScrollBarWidth : 0) - bordersize * 2, textboxclienth); //System.Diagnostics.Debug.WriteLine("text box size " + textboxclienth + " Lines " + linesinbox ); ScrollBar.Location = new Point(ClientRectangle.Width - ScrollBarWidth - bordersize, bordersize); ScrollBar.Size = new Size(ScrollBarWidth, textboxclienth); //System.Diagnostics.Debug.WriteLine("layout Scroll State Lines: " + LineCount + " FVL: " + firstVisibleLine + " textlines " + textboxlinesestimate); }
private void UpdateVscroll() // from the richtext, set the scroll bar { int firstVisibleLine = unchecked ((int)(long)TextBox.SendMessage(EM_GETFIRSTVISIBLELINE, (IntPtr)0, (IntPtr)0)); int linecount = unchecked ((int)(long)TextBox.SendMessage(EM_GETLINECOUNT, (IntPtr)0, (IntPtr)0)); //Console.WriteLine("Scroll State Lines: " + linecount + " FVL: " + firstVisibleLine + " textlines " + textboxlinesestimate ); ScrollBar.SetValueMaximumLargeChange(firstVisibleLine, linecount - 1, textboxlinesestimate); if (ScrollBar.IsScrollBarOn != visibleonlayout) // need to relayout if scroll bars pop on { PerformLayout(); } }