c# - 尝试在 Windows 窗体中修改滚轮的自定义事件
问题描述
当您滚动到它的底部时,我试图让我的 ListBox 自动加载更多项目。为此,我需要一个滚动事件。
默认的 listBox 没有滚动事件。我设法找到了一些代码,在其中创建了一个新类并从默认列表框继承了所有内容。我成功地添加了滚动事件。
当通过鼠标单击使用滚动条时,覆盖工作完美,但不幸的是,当使用滚轮时不会捕获事件。
我试过优化它,所以它也会拿起滚轮,但没有成功。
我想修改的类,所以它也会拿起滚轮。
using System;
using System.Windows.Forms;
public class BetterListBox : ListBox
{
// Event declaration
public delegate void BetterListBoxScrollDelegate(object Sender, BetterListBoxScrollArgs e);
public event BetterListBoxScrollDelegate Scroll;
// WM_VSCROLL message constants
private const int WM_VSCROLL = 0x0115;
private const int SB_THUMBTRACK = 5;
private const int SB_ENDSCROLL = 8;
protected override void WndProc(ref Message m)
{
// Trap the WM_VSCROLL message to generate the Scroll event
base.WndProc(ref m);
if (m.Msg == WM_VSCROLL)
{
int nfy = m.WParam.ToInt32() & 0xFFFF;
if (Scroll != null && (nfy == SB_THUMBTRACK || nfy == SB_ENDSCROLL))
Scroll(this, new BetterListBoxScrollArgs(this.TopIndex, nfy == SB_THUMBTRACK));
}
}
public class BetterListBoxScrollArgs
{
// Scroll event argument
private int mTop;
private bool mTracking;
public BetterListBoxScrollArgs(int top, bool tracking)
{
mTop = top;
mTracking = tracking;
}
public int Top
{
get { return mTop; }
}
public bool Tracking
{
get { return mTracking; }
}
}
}
解决方案
推荐阅读
- spring - 春季自动配置
- python - 矩阵的整数数组索引后的维度不一致
- angular - 以角度动态加载嵌套组件?
- django - sorl.thumbnail 没有在我的视图中创建缩略图
- node.js - Node JS 插件 - NAN 与 N-API?
- sass - 您可以从外部托管 (cdn) sass 文件中导入 sass 变量并在您的项目中使用它吗?
- python - 从 Flask 中的 HTTP POST 请求中读取图像文件并将其转换为 PIL 图像
- paypal - 如何获得访问令牌?- Flutter 中的 PayPal
- html - 不同状态Angular 6的图标颜色
- java - PALIN- 下一个回文 - 一个 SPOJ 问题