我想在用户控件中选择控件时以编程方式从用户控件向其创建者发送鼠标单击。
我试过了:
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());
但我没有成功收到家长的活动。
也许还有另一种方法可以让鼠标点击下来?
由于
答案 0 :(得分:2)
您可以使用Control.InvokeOnClick
触发父表单的点击事件
有关详细信息,请查看此stackoverflow post
答案 1 :(得分:-1)
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
}
}