Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if a Windows forms scroll bar is scrolled all the way down?

I have a rich text box which serves as a log. The log automatically scrolls itself down when a new message is appended, which is good. The only problem is when the user wants to view something in the log from before; if a new message is appended, the box automatically scrolls all the way down and prevents the user from seeing anything. I would like to be able to check if the rich text box is scrolled all the way down, and if it isn't not scroll down.

Currently I can get the scroll position in the virtual text space (SendMessage with EM_GETSCROLLPOS). I can also get scroll bar info with GetScrollBarInfo pinvoke. But how do I figure out what the bottom of the virtual text space is?

Thanks!

like image 518
jakobbotsch Avatar asked Nov 06 '22 01:11

jakobbotsch


1 Answers

Use a vScrollBar control for your RichTextBox and handle its Scroll event

    private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
    {
        if (e.Type == ScrollEventType.Last)
        {
            //scrollbar is all the way down
        }
        else
        {
            //user has scrolled up
        }
    }
like image 88
Saeb Amini Avatar answered Nov 09 '22 07:11

Saeb Amini