DateTime lastClickDate = DateTime.Now;
int xPosition = Cursor.Position.X;
int yPosition = Cursor.Position.Y;
private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
{
//You can change the value 1200 as you want.
if ((DateTime.Now - lastClickDate).TotalMilliseconds < 1200)
{
//Just for example I have given as equals it is better to allow
//some variation since mouse may be moved a little during clicks
if(Cursor.Position.X==xPosition && Cursor.Position.Y==yPosition)
{
MessageBox.Show("double clicked");
}
}
this.Text = (DateTime.Now - lastClickDate).TotalMilliseconds.ToString();
lastClickDate = DateTime.Now;
}
2条答案
按热度按时间suzh9iv81#
如果你想管理一个没有双击事件的控件,你可以使用timestamp来计算点击之间的时间差。比如:
d8tt03nd2#
也许(DateTime.Now - lastClickDate).毫秒代替(DateTime.Now - lastClickDate).毫秒会更好。
除了前面的答案,我建议添加鼠标指针的位置。
Cursor.Position
将在这方面有所帮助。