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;
}
}