Is it possible to fire a DoubleClick
event on a ListView
programmatically? Without needing to know the location/signature of the event handler?
if I understood what you want instead doing so:
private void MouseDoubleClick(object sender, EventArgs e)
{
//some code on mouse double click
}
make:
private void MethodToExecuteOnDoubleClick()
{
//some code on mouse double click
}
private void MouseDoubleClick(object sender, EventArgs e)
{
MethodToExecuteOnDoubleClick();
}
and then you can call MethodToExecuteOnDoubleClick() whenever you want without need to rise doubleclick event
For simulate mouse click you can do something like this:
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
//....
[DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;
public void DoMouseClick()
{
//Call the imported function with the cursor's current position
int X = Cursor.Position.X;
int Y = Cursor.Position.Y;
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
}
//...
}
I blogged about that a while ago: Simulate a Click ; it is not a real click, but it triggers the event handlers. The blog say "OnClick", replace it with "OnDoubleClick" and you should be fine.
最好创建一个封装控件并处理其中可能需要的任何逻辑。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.