<summary>
Magnetic form Functions
</summary>
<param name= "Form" > Form controls (General pass this) </param>
<param name= "Space" > Custom distance from the edge of the screen </param>
<param name= "Isworkingarea" > whether to do this in the screen workspace (true means that the taskbar is not included, false includes the entire screen area) </param>
public void Form_welt (Control Form, int space, BOOL Isworkingarea)
{
Gets the x, y coordinates of the upper-left corner of the form
int x = form. location.x;
int y = form. LOCATION.Y;
int SW = 0;
int SH = 0;
if (Isworkingarea)
{
Gets the width and height of the screen's workspace (excluding the taskbar)
SW = Screen.PrimaryScreen.WorkingArea.Width;
SH = Screen.PrimaryScreen.WorkingArea.Height;
}
Else
{
Get the width and height of the entire screen (including the taskbar)
SW = Screen.PrimaryScreen.Bounds.Width;
SH = Screen.PrimaryScreen.Bounds.Height;
}
If the distance between the left edge of the form and the left edge of the screen is within a user-defined range, the left Welt is performed
if ((x <= space && x > 0) | | (Math.Abs (x) <= space && x < 0)) Math.Abs (x) is the absolute value
{
Form. Location = new Point (0, y);
}
If the distance between the top edge of the form and the top edge of the screen is within a user-defined range, the upper Welt is executed
if ((Y <= space && y > 0) | | (Math.Abs (y) <= space && y < 0))
{
Form. Location = new Point (x, 0);
}
The distance between the right edge of the form and the right edge of the screen
int rightw = Sw-form. right;
The distance between the bottom edge of the form and the bottom edge of the screen
int bottomw = Sh-form. Bottom;
Judging the situation on the right
if (rightw <= space && form. Right < SW) | | (Math.Abs (RIGHTW) <= space && rightw < 0))
{
Form. Location = new Point (sw-form. Width, y);
}
Judging the situation below
if (bottomw <= && form. Bottom < SH) | | (Math.Abs (BOTTOMW) <= space && bottomw < 0))
{
Form. Location = new Point (x, Sh-form. Height);
}
}
See thousands of listening to the window can be close to the edge of the screen to paste on the edge feel good, I also have this need, so write this method, test the feeling is pretty good, haha ~
When you use it, just call it in the Form_move (Object Sender,eventages e) Event of the form you want to apply.
PS: But sometimes the form may be more flash, this may be the code is still to be improved, or in the Form_move event to call is not appropriate, anyway, the function is realized, if there is a better way, welcome to reply to the Exchange AH ~
C # Easy to implement magnetic windows