ListView控件onScroll事件 [英] ListView onScroll event
问题描述
我编程一个简单的C#应用程序,我需要在列表视图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#是没有LOWORD宏象在C ++中,我需要切换到检测像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.
有什么办法如何更换LOWORD宏在C#中?
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;
实际的code视察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屋!