IMessageFilter
以您的主要形式实施:
public partial class YourForm : Form, IMessageFilter
{
// Your code.
public bool PreFilterMessage ( ref Message m )
{
if ( m.Msg == 0x20A )
{
NativeMethods.SendMessage ( controlToScroll.Handle , m.Msg , m.WParam , m.LParam );
return true;
}
return false;
}
}
通过在其构造函数中调用以下内容,将您的表单注册为消息过滤器。
Application.AddMessageFilter ( this );
SendMessage
具有以下签名:
internal class NativeMethods
{
[DllImport ( "user32.dll" , CharSet = CharSet.Auto )]
public static extern IntPtr SendMessage ( IntPtr hWnd , Int32 Msg , IntPtr wParam , IntPtr lParam );
}