C # Implementation Form Drag to screen edge Auto Hide _c# Tutorial

Source: Internet
Author: User
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 ();
}

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.