[英]Can the mouse scroll wheel always affect a panel?
Not sure if I can word this right but here we go. 不知道我是否可以说正确的话,但是我们走了。
I have my application which has a couple of text boxes and a panel with a scroll bar. 我的应用程序有几个文本框和一个带有滚动条的面板。 I want the mouse scroll wheel to always affect the panel.
我希望鼠标滚轮始终影响面板。 Is there a way of doing this?
有办法吗? Currently when I change focus form the panel to the text boxs the scroll wheel stops working for the panel.
目前,当我将焦点从面板更改为文本框时,滚轮将停止为该面板工作。
Thanks in advance 提前致谢
You can do this with a PreFilterMessage. 您可以使用PreFilterMessage进行此操作。 Firstly, change your form to implement IMessageFilter as in:
首先,更改表单以实现IMessageFilter,如下所示:
public partial class Form1 : Form, IMessageFilter
Then in the constructor add the message filter: 然后在构造函数中添加消息过滤器:
public Form1()
{
InitializeComponent();
Application.AddMessageFilter(this);
}
Then implement the IMessageFilter interface: 然后实现IMessageFilter接口:
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == WM_MOUSEWHEEL)
{
SendMessage(panel1.Handle, m.Msg, m.WParam, m.LParam);
return true;
}
return false;
}
And you will also need the following: 并且您还需要以下内容:
private const int WM_MOUSEWHEEL = 0x020A;
[DllImport("user32.dll")]
private static extern IntPtr WindowFromPoint(Point pt);
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.