我已經重寫了UserControl級別的WndProc來檢測MouseDown,MouseUp和MouseMove到在該UserControl中添加的任何控件。C#覆蓋控制級別的WndProc來檢測
protected override void WndProc(ref Message m)
{
Point mouseLoc = new Point();
switch (m.Msg)
{
case WM_LBUTTONDOWN:
System.Diagnostics.Debug.WriteLine("mouse down");
//this.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, mouseLoc.X, mouseLoc.Y, 0));
break;
case WM_LBUTTONUP:
System.Diagnostics.Debug.WriteLine("mouse up");
//this.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, mouseLoc.X,mouseLoc.Y, 0));
break;
case WM_MOUSEMOVE:
int lParam = m.LParam.ToInt32();
//mouseLoc.X = lParam & 0xFFFF;
//mouseLoc.Y = (int)(lParam & 0xFFFF0000 >> 16);
mouseLoc.X = (Int16)m.LParam;
mouseLoc.Y = (Int16)((int)m.LParam >> 16);
System.Diagnostics.Debug.WriteLine("mouse move: " + mouseLoc.X + ", " + mouseLoc.Y);
//this.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, mouseLoc.X,mouseLoc.Y, 0));
break;
}
base.WndProc(ref m);
}
當鼠標指針在用戶控件,但是當鼠標指針在其他控件(我的用戶裏面)這是行不通的MouseMove,向下和向上的工作。
我做錯了什麼?
目前正在開發一個輕彈和滾動控制。
我試圖在輸出窗口中獲取m.Msg,而鼠標指針位於其他控件上,並顯示528和33.您認爲這是什麼? – jaysonragasa 2010-05-05 06:34:35