2009-06-27 74 views
0

我想以編程方式在usercontrol中選擇一個控件時,從usercontrol向其創建者發送鼠標點擊。在.net中發送鼠標點擊消息

我曾嘗試:

private const int MOUSEEVENTF_LEFTDOWN = 0x02; 
private const int MOUSEEVENTF_LEFTUP = 0x04; 

    [DllImport("user32.dll")] 
    private static extern void mouse_event(
    UInt32 dwFlags, // motion and click options 
    UInt32 dx, // horizontal position or change 
    UInt32 dy, // vertical position or change 
    UInt32 dwData, // wheel movement 
    IntPtr dwExtraInfo // application-defined information 
    ); 

    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr()); 
    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr()); 

但我沒有在父recieving事件的任何成功。

也許還有另一種鼠標點擊的方式嗎?

感謝

回答

2

您可以使用Control.InvokeOnClick觸發你的父窗體的單擊事件。
查看詳細信息post瞭解詳情

0
class Parent : Control { 
    private Control child; // some child control 

    ... 

    child_OnClick(object sender, EventArgs e) { //subscribed to child Click event 
    this.OnClick(e); //Fire parent's click event 
    } 
}