Shooting event when the scroll bar reaches the bottom of the panel

I have a winform application in which I want the event to fire when the scroll bar reaches the bottom of the panel.

I tried this:

private void Panel1_Scroll(object sender, ScrollEventArgs e) { //some operation } 

But this is a shooting event every time I scroll the scroll bar, when I do not get to the end.

How to do it?

+5
source share
4 answers

Check the ScrollEventArgs.NewValue Property. Like this:

 private void Panel1_Scroll(object sender, ScrollEventArgs e) { if (e.NewValue == panel1.VerticalScroll.Maximum - panel1.VerticalScroll.LargeChange + 1) { if(e.NewValue != e.OldValue) // Checking when the scrollbar is at bottom and user clicks/scrolls the scrollbar { MessageBox.Show("Test"); // Some operation } } } 
+4
source
 if (e.ScrollOrientation == ScrollOrientation.VerticalScroll) { VScrollProperties vs = panel2.VerticalScroll; if (e.NewValue == vs.Maximum - vs.LargeChange+1) { //Do your stuff } } 
+2
source
 private void panel1_Scroll(object sender, ScrollEventArgs e) { if(e.ScrollOrientation == ScrollOrientation.HorizontalScroll) { if(panel1.HorizontalScroll.Value == panel1.HorizontalScroll.Maximum) { //end } } else { if (panel1.VerticalScroll.Value == panel1.VerticalScroll.Maximum) { //end } } } 
0
source
  if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll) { if (e.NewValue + panel1.Width > panel1.HorizontalScroll.Maximum) MessageBox.Show("End of Horizontal Scroll"); } else { if (e.NewValue + panel1.Height > panel1.VerticalScroll.Maximum) MessageBox.Show("End of Vertical Scroll"); } 
0
source

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


All Articles