How to can I control the Scrollbar on the Textbox...??

Hi.

I'm writting C# Application.
I want to know thumb position on the Scrollbar on the Textbox.
(or How to can I control the Scollbar on the Textbox )

The System.Windows.Forms.Textbox didn't have any members to control it.

Could you help me


Answer this question

How to can I control the Scrollbar on the Textbox...??

  • Michael J Brown

    This is possible similar to the way I did it for the ListBox. However, it has very little practical value for a TextBox. Its scrolling behavior is controlled by the caret position, available as the SelectionStart property. You'd use the ScrollToCaret() method to force the TextBox to scroll to make the caret visible.


  • Amir__

    I have a multiline textbox in C# and am trying to use the Insert() and Delete() methods. Whenever I do, the textbox reloads and scrolls to the first line in the textbox. If I use the SelectionStart property and then the ScrollToCaret() method after using Insert() or Delete() the first line of the textbox is different than before I made the call causing the display to seem to move to the user. How can I keep the same line at the top of the textbox after using Insert() or Delete()


  • connect2sandeep

    You'll have to P/Invoke the GetScrollInfo() API function to find out where the thumb is at. Try this:

    using System.Runtime.InteropServices;
    ...
    public static double GetScrollPercentage(TextBoxBase ctl) {
    SCROLLINFO info = new SCROLLINFO();
    info.cbSize = Marshal.SizeOf(info);
    info.fMask = 0x17;
    GetScrollInfo(ctl.Handle, 1, ref info);
    if (info.nMax <= info.nPage + 1) return 100;
    return 100.0 * info.nPos / (info.nMax - info.nPage + 1);
    }

    [DllImport("user32.dll")]
    private static extern bool GetScrollInfo(IntPtr hwnd, int fnBar, ref SCROLLINFO lpsi);
    [StructLayout(LayoutKind.Sequential)]
    struct SCROLLINFO {
    public int cbSize;
    public uint fMask;
    public int nMin;
    public int nMax;
    public uint nPage;
    public int nPos;
    public int nTrackPos;
    }



  • arvindbksc

    Thanks a lot, nobugz!

  • Gurpreet Singh Gill


    Thanks, nobugz.

    I've done auto scroll for the Textbox. but, I've one more question.
    I want to know whether thumb position is bottom or not when input to the Textbox.
    This problem wasn't solved using WinProc and WM_VSCROLL.


  • How to can I control the Scrollbar on the Textbox...??