C # automatically hide a form that is dragged to the edge of the screen

Source: Internet
Author: User

Below Source code : (Note: Hide is the form name) CopyCode The Code is as follows: Private void hide_load (Object sender, eventargs E)
{
System. Windows. Forms. Timer stoprecttimer = new system. Windows. Forms. Timer ();
Stoprecttimer. Tick + = new eventhandler (timerstmtick );
Stoprecttimer. interval = 100;
Stoprecttimer. Enabled = true;
}
Private void timereffectick (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.