The following gives the source code: (Note: Hide is the form name)
Copy Code code as follows:
private void Hide_load (object sender, EventArgs e)
{
System.Windows.Forms.Timer Stoprecttimer = new System.Windows.Forms.Timer ();
Stoprecttimer.tick + = new EventHandler (Timer1_Tick);
Stoprecttimer.interval = 100;
Stoprecttimer.enabled = true;
}
private void Timer1_Tick (object sender, EventArgs e)
{
if (this. Bounds.contains (cursor.position))
{
Switch (this. Stopaanhor)
{
Case Anchorstyles.top:
This. Location = new Point (this. location.x, 0);
Break
Case Anchorstyles.left:
This. Location = new Point (0, this. LOCATION.Y);
Break
Case Anchorstyles.right:
This. Location = new Point (screen.primaryscreen.bounds.width-this. Width, this. LOCATION.Y);
Break
}
}
Else
{
Switch (this. Stopaanhor)
{
Case Anchorstyles.top:
This. Location = new Point (this. Location.x, (this. HEIGHT-2) * (-1));
Break
Case Anchorstyles.left:
This. Location = new Point (( -1) * (this. Width-2), this. LOCATION.Y);
Break
Case Anchorstyles.right:
This. Location = new Point (Screen.primaryscreen.bounds.width-2, this. LOCATION.Y);
Break
}
}
}
Internal AnchorStyles stopaanhor = Anchorstyles.none;
private void Mstopanhor ()
{
if (this. Top <= 0)
{
Stopaanhor = Anchorstyles.top;
}
else if (this. Left <= 0)
{
Stopaanhor = Anchorstyles.left;
}
else if (this. Left >= Screen.primaryscreen.bounds.width-this. Width)
{
Stopaanhor = Anchorstyles.right;
}
Else
{
Stopaanhor = Anchorstyles.none;
}
}
private void Hide_locationchanged (object sender, EventArgs e)
{
This.mstopanhor ();
}