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

匿名 (未验证) 提交于 2019-12-03 00:52:01

问题:

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!

回答1:

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         }     } 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!