Allways on top window(form) c#

G

gRANdOOM

A simple way to do put a window(form) in front of all other windows
(entire desctop) is to use the following conde.

[DllImport("user32")] public static extern int SetWindowPos(int hwnd,
int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
private Form2 frm;

public void SetTopmost(IntPtr hwnd ,bool bTopmost)
{
long i = 0;
if (bTopmost == true)
{
i = SetWindowPos(hwnd.ToInt32() , -
1,Screen.PrimaryScreen.Bounds.Width/2 - 160/2,
Screen.PrimaryScreen.Bounds.Height/2 - 40/2, 160, 40, 0);
}
else
{
frm.Dispose();
}
}

public void StartForm()
{
frm = new Form2();
SetTopmost(frm.Handle ,true);
frm.Show();
}

The code iz copyed from a project.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top