Trigger the double-click event of C # button

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.