C # How to Implement floating windows

Source: Internet
Author: User

Public class WIN32API
{
[System. runtime. interopservices. dllimport ("user32.dll")]
Public static extern bool ptinrect (ref rectangle R, point P );
}

/// <Summary>
/// Dock to the top
/// </Summary>
Private void berthtop (Object sender, eventargs E)
{
System. Drawing. Point pp = new point (cursor. position. X, cursor. position. y );
Rectangle rects = new rectangle (this. Left, this. Top, this. Left + this. Width, this. Top + this. Height );
If (this. Top <0) & WIN32API. ptinrect (ref rects, pp ))
{
This. Top = 0;
}
Else if (this. Top>-5) & (this. Top <5 )&&! (WIN32API. ptinrect (ref rects, pp )))
{
This. Top = 5-This. height;
}
}

Private void settouming ()
{
Frmsetopaticy OPA = new frmsetopaticy (this );
Opa. startposition = formstartposition. centerscreen;
Opa. showdialog (this );
}

 

 

 

// Private void timereffectick (Object sender, eventargs E)
//{
// System. Drawing. Point pp = new point (cursor. position. X, cursor. position. Y); // obtain the coordinate point of the mouse on the screen
// Rectangle rects = new rectangle (this. left, this. top, this. left + this. width, this. top + this. height); // store the current form in the area of the screen
// If (this. Top <0) & WIN32API. ptinrect (ref rects, pp) // when the cursor is in the current form, and the top attribute of the form is smaller than 0
// This. Top = 0; // set the top attribute of the form to 0, that is, to close the upper edge of the window to the top
// Else if (this. Top>-5 & this. Top <5 &&! (WIN32API. ptinrect (ref rects, pp) // when the distance between the upper border of the form and the top of the screen is less than 5
// This. Top = 5-This. height; // hide the QQ form to the top of the screen
//}

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.