/// <Summary>
/// Magnetic form functions
/// </Summary>
/// <Param name = "form"> Form Control (generally pass this command) </Param>
/// <Param name = "space"> Custom distance from the screen edge </Param>
/// <Param name = "isworkingarea"> Whether to perform this operation in the screen workspace (true indicates that the taskbar is not included, and false indicates that the entire screen range is included) </Param>
Public Void Form_welt (control form, Int Space, Bool Isworkingarea)
{
// Obtains the X and Y coordinates in the upper left corner of the form.
Int X = Form. Location. X;
Int Y = Form. Location. Y;
IntSW= 0;
IntSh= 0;
If (Isworkingarea)
{
// Obtain the width and height of the workspace (excluding the taskbar) on the screen.
SW = Screen. primaryscreen. workingarea. width;
Sh = Screen. primaryscreen. workingarea. height;
}
Else
{
// Obtain 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 the user-defined range, the left side is pasted.
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 the user-defined range, the top edge is pasted.
If (Y <= Space && Y > 0 ) | (Math. Abs (y) <= Space && Y < 0 ))
{
Form. Location = New Point (X, 0 );
}
// distance between the right edge of the form and the right edge of the screen
int rightw = SW - form. right;
// distance between the bottom edge of the form and the bottom edge of the screen
int bottomw = Sh - form. bottom;
// Determine 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 );
}
// Determine the following conditions
If (Bottomw <= 10 && Form. Bottom < SH) | (Math. Abs (bottomw) <= Space && Bottomw < 0 ))
{
Form. Location = New Point (x, SH - Form. Height );
}
}
I think it is good to see a quiet window that can be pasted on the edge when it is close to the edge of the screen. I also have this need. So I wrote this method and tested it quite well, haha ~
you only need to call the form_move (Object sender, eventages e) event of the form you want to apply.
PS: However, sometimes the form may flash, this may be because the Code remains to be improved, or it is not suitable to be called in the form_move event. The function is actually implemented, if anyone has a better method, please feel free to reply ~