ListView onScroll 事件 [英] ListView onScroll event

查看:17
本文介绍了ListView onScroll 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个简单的 C# 应用程序,我需要在 Listview 上使用 onScroll 事件.所以我创建了类 ListviewEx 女巫继承了原来的 ListView.我找到了如何从 WinAPI 检测滚动消息并修改了 WndProc 方法.现在我有了这个 WndProc:

I’m programming one easy C# application, and i need onScroll event on Listview. So i created class ListviewEx witch inherits original ListView. I found how to detect scroll message from WinAPI and i modified WndProc method. Now i have this WndProc:

protected override void WndProc(ref Message m) 
{ 
    base.WndProc(ref m); 

    if (m.Msg == WM_VSCROLL) 
    { 
        onScroll(this, new EventArgs()); 
    } 
}

但问题是,我不知道如何检测有关滚动的信息.这些数据应该在 WParam 中,但在 C# 中没有像 C++ 那样的 LOWORD 宏,我需要切换到检测参数,如 SB_BOTTOM、SB_ENDSCROLL、SB_PAGEUP 等.

But problem is, that I dont know how to detect information about scrolling. This data should be in WParam, but in C# is no LOWORD macro like in C++ and i need switch to detect parameters like SB_ BOTTOM, SB_ ENDSCROLL, SB_PAGEUP etc.

有什么方法可以替换 C# 中的 LOWORD 宏吗?

Is there any way how to replace LOWORD macro in C# ?

或者其他方式如何检测有关滚动的必要参数?

Or other way how to detect necessary parameters about scrolling?

推荐答案

您可以定义 WParam 常量如下:

You can define WParam constants as followed:

private const int WM_HSCROLL = 0x114;
private const int WM_VSCROLL = 0x115;

private const int SB_HORZ = 0;
private const int SB_VERT = 1;

private const int SB_LINELEFT = 0;
private const int SB_LINERIGHT = 1;
private const int SB_PAGELEFT = 2;
private const int SB_PAGERIGHT = 3;
private const int SB_THUMBPOSITION = 4;
private const int SB_THUMBTRACK = 5;
private const int SB_LEFT = 6;
private const int SB_RIGHT = 7;
private const int SB_ENDSCROLL = 8;

private const int SIF_TRACKPOS = 0x10;
private const int SIF_RANGE = 0x1;
private const int SIF_POS = 0x4;
private const int SIF_PAGE = 0x2;
private const int SIF_ALL = SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS;

检查 WParam 的实际代码是这样的:

The actual code to inspect the WParam would be something like this:

if (m.Msg == WM_VSCROLL)
{

        ScrollInfoStruct si = new ScrollInfoStruct();
        si.fMask = SIF_ALL;
        si.cbSize = (uint)Marshal.SizeOf(si);
        GetScrollInfo(msg.HWnd, SB_VERT, ref si);
        if (msg.WParam.ToInt32() == SB_ENDSCROLL)
        {
            ScrollEventArgs sargs = new ScrollEventArgs(ScrollEventType.EndScroll, si.nPos);
            onScroll(this, sargs);
        }
}

pinvoke.net 是一个很好的网站,可以获取 windows32 API 中使用的常量值,而无需自己检查头文件.

pinvoke.net is a great site to get the constant values used in windows32 API without having to inspect header files yourself.

看这个例子

这篇关于ListView onScroll 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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