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? (Improvement)
Declare this delegate outside the class:
Public Delegate void mouseclickevent (Object sender, mouseeventargs E );
Rewrite some methods in the class:
/// <Summary>
/// Indicates whether the mouse has been lifted by pressing the mouse.
/// </Summary>
Private bool _ ismouseleftbuttondownmoveup = false;
Protected override void onmousedown (mouseeventargs E)
{
This. _ ismouseleftbuttondownmoveup = false;
Base. onmousedown (E );
}
Protected override void onmousemove (mouseeventargs E)
{
If (E. Button = mousebuttons. Left)
{
This. _ ismouseleftbuttondownmoveup = true;
}
Base. onmousemove (E );
}
Protected override void onmouseup (mouseeventargs E)
{
Base. onmouseup (E );
If (! (This. allowdragmove & this. _ ismouseleftbuttondownmoveup ))
{
// If it is clicked and its position is still within the control range, the left button is clicked.
If (E. clicks = 1 & this. Inshell (E. X, E. Y) & E. Button = mousebuttons. Left)
{
// Trigger the mouseclick event
This. mouseclick (this, e );
}
}
This. _ ismouseleftbuttondownmoveup = false;
}
Private bool inbounds (int x, int y)
{
Point P = This. pointtoscreen (new point (x, y ));
Point P1 = This. pointtoscreen (new point (0, 0 ));
Point P2 = This. pointtoscreen (new point (this. Width, this. Height ));
If (p. x <p1.x)
{
Return false;
}
If (p. x> p2.x)
{
Return false;
}
If (P. Y <p1.y)
{
Return false;
}
If (P. Y> p2.y)
{
Return false;
}
Return true;
}
Public event mouseclickevent mouseclick;
Private void shell_mouseclick (Object sender, mouseeventargs E)
{
// Do something you need
}