C # mouse events

3.20 mouse events
derived from the System.Windows.Forms.Control class controls have mouse events, Click event of the nature of the controls
on also mouse events. Some controls as well as a separate mouse events, such as Form. Mouse events are:

? MouseDown: This event is generated if the mouse is located in the control area, press the mouse button.

? MouseUp: This event is generated if the mouse is located in the control area, lift the mouse button.

? MouseMove: If you move the mouse in the control area, produce the event.

? MouseEnter: mouse enters the control area, produce the event.

? MouseLeave: mouse leaves the control area, produce the event.

Mouse event handlers generally have two parameters:

The first parameter (object sender) is the target value generation property Name of the event,

For example, increasing the function of the event MouseDown event of Form1,

Click Form1, the first parameter represents the sender Form1 object.

(MouseEventArgs e) event handler is the second parameter,

some of the information representing events, different events, represented by the information is not the same,

Mouse down event handler,

eX is the x coordinate of the mouse position when the event occurs, eY for the y coordinate of the mouse position when the event occurs,

e.Button is MouseButtons.Left, clicked the mouse button, and so on,

Right and Middle represent the right and middle button.

e.Clicks to click the number, if more than two times, compared to double-click.

Examples e3_12:

Form of the designated area, double-click the left mouse button, double-click the display position with the Label control.

Left corner of the specified region (20, 20), width 200, height 200.

(1) the establishment of a new project. Put a Label control to the form. Attribute Name = label1.

(2) Panel window controls can be divided into a plurality of regions. Panel discharge control to the form attribute = 20 is location.x,
location.y = 20 is, attributes Width = 200, Height = 200, attributes Name = p1.

(3) increase as a function of the event MouseDown event Panel as follows:
Private void p1_MouseDown (Object SENDER, System.Windows.Forms.MouseEventArgs E)
{IF (e.Button == MouseButtons.Left && e.Clicks>. 1) // If double-clicking left
Label1.Text = "X-:" eXToString + () + ", the Y:" + eYToString ();
}

(4) compile, run, respectively, double-click the left mouse button in the designated area and the area outside, look at the results. Respectively, in the designated area and
double-click the right mouse button outside the area, look at the results.

Guess you like

Origin www.cnblogs.com/liudongjun/p/12212756.html