Implementation of the eyesbaby function: Window dragging and Scaling

Source: Internet
Author: User

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

 

 

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.