In winform, the form dragging is mainly completed by the mouse move event, the mouse press event (mousedown), and the mouse release event (mouseup.
The following detailsCode:
Private Point mouseoffset; // Record the coordinates of the mouse pointer
/// <Summary>
/// Move mouse event
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private Void Form1_mousemove ( Object Sender, mouseeventargs E)
{
If (Ismousedown)
{
Point mousepos = Control. mouseposition;
Mousepos. offset (mouseoffset. X, mouseoffset. y );
// Set the window position to move the cursor
Location = Mousepos;
}
}
/// <Summary>
/// Mouse press event
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private Void Form1_mousedown ( Object Sender, mouseeventargs E)
{
Int Xoffset;
Int Yoffset;
If (E. Button = Mousebuttons. Left)
{
Xoffset = - E. x - Systeminformation. framebordersize. width;
Yoffset = - E. Y - Systeminformation. captionheight -
Systeminformation. framebordersize. height;
Mouseoffset = New Point (xoffset, yoffset );
Ismousedown = True ;
}
}
/// <Summary>
/// Mouse release event
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private Void Form1_mouseup ( Object Sender, mouseeventargs E)
{
// Modify the ismousedown value of the mouse state
// Make sure that the form is moved only when the left mouse button is pressed and moved.
If (E. Button = Mousebuttons. Left)
{
Ismousedown = False ;
}
}
Scroll the axis to control the window size:
You need to move the mouse to the scroll event (mousewheel ). The values of the event parameter mouseeventargs. Delta are 120 and-120, respectively.
The Code is as follows:
/// <Summary>
/// Scroll events
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Void Form1_mousewheel ( Object Sender, mouseeventargs E)
{
Size t = Picturebox1.size;
T. Width + = E. Delta;
T. Height + = E. Delta;
// Control window width greater than 100px
If (E. Delta = 120 | ( This . Size. Height > 100 && This . Size. Width > 200 ))
This . Size = T;
// Message prompt Center
Lblmsg. Location = New Point (( This . Width - Lblmsg. width) / 2 ,( This . Height - Lblmsg. Height) / 2 );
}
In fact, in eyesbaby, the image control is used to control the size and drag position of the form.
Source code: Http://eyesbaby.codeplex.com/
Installation: http://files.cnblogs.com/yizhuqing/EyesBabySetup10.zip
My first utility-eye protectionProgram(Eyesbaby)
Eyesbaby1.0 help documentation
Implementation of the eyesbaby function: Window dragging and Scaling
Add characters to the image control using the eyesbaby Function
Eyesbaby function implementation-Windows foreground color Regulator
Software Update for eyesbaby function implementation
Implementation of the eyesbaby function: Window fading effect
Welcome to the eyesbaby Development Team
Eyesbaby demand feedback team