Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firing event when scroll bar reaches the bottom of panel

I have a winform application where I want a event to be fired when the scrollbar reaches the bottom of panel.

I tried this:

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

But it is firing event everytime I scroll the Scrollbar not when I reach the end.

How to achieve this ?

like image 626
Digambar Malla Avatar asked Dec 15 '15 10:12

Digambar Malla


1 Answers

Check 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
       }
    }
}
like image 56
Salah Akbari Avatar answered Sep 23 '22 10:09

Salah Akbari