簡體   English   中英

鼠標滾輪會始終影響面板嗎?

[英]Can the mouse scroll wheel always affect a panel?

不知道我是否可以說正確的話,但是我們走了。

我的應用程序有幾個文本框和一個帶有滾動條的面板。 我希望鼠標滾輪始終影響面板。 有辦法嗎? 目前,當我將焦點從面板更改為文本框時,滾輪將停止為該面板工作。

提前致謝

您可以使用PreFilterMessage進行此操作。 首先,更改表單以實現IMessageFilter,如下所示:

public partial class Form1 : Form, IMessageFilter

然后在構造函數中添加消息過濾器:

public Form1()
{
  InitializeComponent();
  Application.AddMessageFilter(this);
}

然后實現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;
}

並且您還需要以下內容:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM