C # Call the API to realize that the form is always at the top

Source: Internet
Author: User

Class Win32
{
[DllImport ("user32.dll", EntryPoint = "SetWindowPos")]
Public static extern bool SetWindowPos (
Int hWnd, // window handle
Int hWndInsertAfter, // placement-order handle
Int X, // horizontal position
Int Y, // vertical position
Int cx, // width
Int cy, // height
Uint uFlags); // window positioning flags
Public const int HWND_BOTTOM = 0x1;
Public const uint SWP_NOSIZE = 0x1;
Public const uint SWP_NOMOVE = 0x2;
Public const uint SWP_SHOWWINDOW = 0x40;
}

Private void ShoveToBackground ()
{
Win32.SetWindowPos (int) this. Handle,-1, this. Location. X, this. Location. Y, this. Size. Width, this. Size. Height, 1 );

// Win32.SetWindowPos (
// (Int) this. Handle,
// (Int ),
// 0, 0, 0, 0,
// Win32.SWP _ NOMOVE | Win32.SWP _ NOSIZE | Win32.HWND _ BOTTOM );
}

Private void Bar_Activated (object sender, EventArgs e)
{
// Always at the top
ShoveToBackground ();
}
Private void Bar_Leave (object sender, EventArgs e)
{
// Always at the top
ShoveToBackground ();
}

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.