滚动条到达面板底部时的触发事件

时间:2015-12-15 10:58:15

标签: c# winforms events scrollbar panel

我有一个winform应用程序,我希望在滚动条到达面板底部时触发事件。

我试过了:

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

但每当我滚动滚动条时,它都是触发事件。当我到达终点时。

如何实现这一目标?

4 个答案:

答案 0 :(得分:4)

检查ScrollEventArgs.NewValue财产。像这样:

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

答案 1 :(得分:2)

if (e.ScrollOrientation == ScrollOrientation.VerticalScroll)
{
    VScrollProperties vs = panel2.VerticalScroll;
    if (e.NewValue == vs.Maximum - vs.LargeChange+1)
    {
        //Do your stuff
    }
}

答案 2 :(得分:0)

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

答案 3 :(得分:0)

            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");
        }