The click event of usercontrol is valid for both the left and right mouse keys. How does one make it as sensitive as the left mouse button control?

Source: Internet
Author: User

The click event of usercontrol is valid for both the left and right mouse keys. How does one make it as sensitive as the left mouse button control?

The program section in this article has been improved through repeated scrutiny. For details, see "(Improvement) The Click Event of usercontrol is effective for both the left and right mouse keys, how does one make it as sensitive as a button control to the left mouse button?"

In this improved version, the onmouseup method is directly rewritten and a crucial judgment content is added to it. In addition, the mouseclick event is added, similar to the mouseclick event in. NET 2005.

First, let's take a look at what kind of click events I want:

Left mouse button pressed

Left mouse button lifted

The mouse is not moved during this period

This is what I want to click. For implementation, see the following:

Private bool _ isclick = false; // indicates whether the control is clicked.

/// <Summary>

/// The left button is pressed

/// </Summary>

/// <Param name = "sender"> </param>

/// <Param name = "E"> </param>

Private void clickdown (Object sender, system. Windows. Forms. mouseeventargs E)

{

If (E. Button = mousebuttons. Left)

{

This. _ isclick = true;

}

Else

{

This. _ isclick = false;

}

}

/// <Summary>

/// Left-click lift

/// </Summary>

/// <Param name = "sender"> </param>

/// <Param name = "E"> </param>

Private void clickup (Object sender, system. Windows. Forms. mouseeventargs E)

{

If (E. Button = mousebuttons. Left & this. _ isclick = true)

{

This. _ isclick = false

// Write some programs here, which is the place to process the click, or simply get an event, which is also a good choice.

}

}

/// <Summary>

/// Click Cancel

/// </Summary>

/// <Param name = "sender"> </param>

/// <Param name = "E"> </param>

Private void clickcancel (Object sender, system. Windows. Forms. mouseeventargs E)

{

If (E. Button = mousebuttons. Left & this. _ isclick = true)

{

This. _ isclick = false;

}

}

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.