In C #, a button has a DoubleClick event, but it does not appear in the event list. net also blocks this event. No matter how fast you double-click a button, it will not trigger this event.
To trigger the double-click event of the button, we can reload the mousedown event to record the time of each mouse press. If the time of the two clicks is close enough, the double-click method is triggered.
In this way, the double-click effect can be roughly achieved. In fact, the method I used is similar to this. It inherits the button class and reloads the Click Event of the button class, determine the time of the two clicks in the click event. If it is near, the double-click event is triggered. Speak nonsense.Code:
Code
// ========================================================== ====================================
//
// Copyright (c) 2007-2008 Hangzhou shiguwen Information Technology Co., Ltd.
// All Rights Reserved
//
// Filename: buttonex
// Description:
//
// Created by Ye Jin at 15:38:24
// Http://adaiye.cnblogs.com
//
// ========================================================== ====================================
Using System;
Using System. Collections. Generic;
Using System. text;
Using System. Windows. forms;
Public ClassButtonex: button
{
Public New EventEventhandler DoubleClick;
Datetime clicktime;
BoolIsclicked= False;
Protected Override VoidOnclick (eventargs E)
{
Base. Onclick (E );
If (Isclicked)
{
Timespan Span = Datetime. Now - Clicktime;
If (Span. milliseconds < Systeminformation. doubleclicktime)
{
DoubleClick ( This , E );
Isclicked = False ;
}
}
Else
{
Isclicked = True ;
Clicktime = Datetime. now;
}
}
}
In this way, you can add a DoubleClick event for the created buttonex button:
Button. DoubleClick + = new eventhandler (button_doubleclick); // double-click a button event