[英]Fire DoubleClick event on ListView in C#
Is it possible to fire a DoubleClick
event on a ListView
programmatically? 是否可以以编程方式在ListView
上触发DoubleClick
事件? 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 然后您可以随时调用MethodToExecuteOnDoubleClick(),而无需引发doubleclick事件
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. 博客上说“ OnClick”,将其替换为“ OnDoubleClick”,就可以了。
最好创建一个封装控件并处理其中可能需要的任何逻辑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.