
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

{
public partial class Form1 : Form
{
static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
static readonly IntPtr HWND_TOP = new IntPtr(0);
static readonly IntPtr HWND_BOTTOM = new IntPtr(1);
const UInt32 SWP_NOSIZE = 0x0001;
const UInt32 SWP_NOMOVE = 0x0002;
const UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE;
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint
uFlags);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, 0,
0, TOPMOST_FLAGS);
}
}
Gian torPosted Jun 23, 2022, 4:51 PM
I copy the exact code, but while the kirtan solution works, my don't. why?
Francis Saa-DittohPosted Jan 10, 2018, 9:53 PM
Exactly what I've been searching for!! Thanks so much. @Clark and @ David, this is to make the window on top of every other Application. "TopMost" only works for a form within you app. E.g. I'm using it to make my App's splash screen appear on top of every other application running
Clark KentPosted Feb 11, 2011, 10:06 AM
it could be done with just 1 code line: this.TopMost = true;
David BozjakeditedPosted Mar 29, 2010, 5:38 AMEdited Mar 29, 2010, 5:41 AM
How is this different from Form.TopMost = true; ? Here is a link from MSDN documentation: http://msdn.microsoft.com/en-us/library/system.windows.forms.form.topmost.aspx