How to determine if the WinForms panel scrolls to the end?

I am developing a WinForms application that has a dashboard containing some user controls. When the panel loads for the first time, it shows 10 user controls. But when it scrolls fully, it needs to load and add additional user controls at the end of the panel. I am trying to achieve this using this code:

private void topicContainer_Scroll(object sender, ScrollEventArgs e) { if (e.NewValue== topicContainer.VerticalScroll.Value) MessageBox.Show("Topics load here"); } 

This is just a test. I don't know what this NewValue really means. So, can you tell me how to complete my task?

+1
source share
4 answers

MSDN does a great job with this. Have you checked this?

Keep in mind the strange behavior of scrollbars: the user can never reach his Maximum value . Read the notes on the ScrollBar.Maximum MSDN Help page.

+3
source

As already mentioned, the scroll bar never reaches its maximum value, and this is due to the fact that the LargeChange property gets factorized into the equation:

 private void topicContainer_Scroll(object sender, ScrollEventArgs e) { VScrollProperties vs = topicContainer.VerticalScroll; if (e.NewValue == vs.Maximum - vs.LargeChange + 1) { // scrolled to the bottom } } 

+ 1 - for offset based on zero. If you set the AutoScrollMinSize height property to 500, the maximum value is actually 499.

+4
source

This function must be placed in a static class.

 public static bool IsScrolledDown(this ContainerControl c) { return !c.VerticalScroll.Visible || c.VerticalScroll.Value == c.VerticalScroll.Maximum - c.VerticalScroll.LargeChange + 1; } 
0
source
 if(topicContainer.VerticalScroll.Value == topicContainer.VericalScroll.Maximum) { } 
-1
source

Source: https://habr.com/ru/post/1238246/


All Articles