滚动条到达面板底部时的触发事件 [英] Firing event when scroll bar reaches the bottom of panel

查看:69
本文介绍了滚动条到达面板底部时的触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我试过这个:

  private   void  Panel1_Scroll(对象发​​件人,ScrollEventArgs e)
{
// 某些操作
}



但每次滚动滚动条时它都会触发。



如何实现这一目标?

解决方案

无论出于何种原因,微软在Windows窗体中检测滚动到底部和右边,都比必要的要复杂得多。 />


Panel的滚动行为存在严重缺陷:ScrollEventArgs.Type字段应该包含Type ScrollEventArgs的枚举值(根据Kornfeld Peter最近的源代码检查)回覆已实施。

  private   void  panel1_Scroll( object  sender,ScrollEventArgs e)
{
VScrollProperties vsp = panel1.VerticalScroll;

int scrollmax = vsp.Maximum - vsp.LargeChange + 1 ;

if (e.NewValue == scrollmax)scrolledToBottom(e.NewValue,scrollmax);
}

// test
private void scrolledToBottom( int nv, int smax)
{
Console.WriteLine( 滚动到底部:{0} {1},nv,smax);
}

注意:



您可以在表单级别创建变量,以保存Panel的VerticalScroll.Maximum和VerticalScroll的值.LargeChange,然后在Form Load Event中初始化它们,或者如果你不在代码中操作那些属性,则在Form的构造函数中初始化它们......或者,如果你操作它们,你需要更新变量。 / BLOCKQUOTE>

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.

How to achieve this ?

解决方案

For whatever reasons Microsoft made detecting scrolling to bottom, and to right, in Windows Forms, much more tricky than was necessary.

The Panel has serious flaws in its scrolling behavior: the ScrollEventArgs.Type field which should hold an enumeration value of Type ScrollEventArgs is (according to Kornfeld Peter's recent source code examination) not really implemented.

private void panel1_Scroll(object sender, ScrollEventArgs e)
{
    VScrollProperties vsp = panel1.VerticalScroll;

    int scrollmax = vsp.Maximum - vsp.LargeChange + 1;

    if (e.NewValue == scrollmax) scrolledToBottom(e.NewValue, scrollmax);
}

// test
private void scrolledToBottom(int nv, int smax)
{
    Console.WriteLine("scrolled to bottom: {0} {1}", nv, smax);
}

Note:

You could create variables at Form level, to hold the values of the Panel's VerticalScroll.Maximum and VerticalScroll.LargeChange, then initialize them in the Form Load Event, or the constructor of the Form if you don't manipulate those properties in your code ... or, if you do manipulate them, you'll need to update the variables.


这篇关于滚动条到达面板底部时的触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆