show a windows form in front of an arbitrary fullscreen application

M

Marcus

How do I do it in c#?

My current solution works sometimes, but sometimes the form comes
behind the fullscreen application.

I am using the following in the forms constructor

this.WindowState = FormWindowState.Normal;
this.Focus();
this.BringToFront();
this.TopLevel = true;

All I want to do is to put a message on the screen, and I want it to be
visible no matter what application has the top level window.

All suggestions are very welcome!

thanks
 
S

Stoitcho Goutsev \(100\)

Marcus,
this.TopLevel = true;

I believe you want to set TopMost to true. TopLevel is true by default.

However there is no top on the the TopMost. When you set form to be TopMost
it will be over all "normal forms", but will
compete with all other topmost that you may have.
 
G

Guest

Hi Marcus,

You might want to use a P/Invoke approach. Namely, you can use User32's
SetForegroundWindow() API to give your window focus without having to set
Window State, TopLevel (Did you mean TopMost ?) and other Form properties.

The declartion for the API is:

[System.Runtime.InteropServices.DllImport("User32")]
private static extern bool SetForegroundWindow(
IntPtr hWnd
);

A call to this function can be done in a Form's Load event handler method:

private void Form1_Load(object sender, EventArgs e)
{
SetForegroundWindow(this.Handle);
}

That way your window will be given focus and it will most likely be in front
of any other windows, even if they consume the whole workspace.
 
S

Stoitcho Goutsev \(100\)

Unless something special is done all applications start with their main
windows on the foreground. I believe this step is redundant.


--
S uvajenie,
Stoitcho Goutsev (100)

Stanimir Stoyanov said:
Hi Marcus,

You might want to use a P/Invoke approach. Namely, you can use User32's
SetForegroundWindow() API to give your window focus without having to set
Window State, TopLevel (Did you mean TopMost ?) and other Form properties.

The declartion for the API is:

[System.Runtime.InteropServices.DllImport("User32")]
private static extern bool SetForegroundWindow(
IntPtr hWnd
);

A call to this function can be done in a Form's Load event handler method:

private void Form1_Load(object sender, EventArgs e)
{
SetForegroundWindow(this.Handle);
}

That way your window will be given focus and it will most likely be in
front
of any other windows, even if they consume the whole workspace.

--
Stanimir Stoyanov
www.stoyanoff.info


Marcus said:
How do I do it in c#?

My current solution works sometimes, but sometimes the form comes
behind the fullscreen application.

I am using the following in the forms constructor

this.WindowState = FormWindowState.Normal;
this.Focus();
this.BringToFront();
this.TopLevel = true;

All I want to do is to put a message on the screen, and I want it to be
visible no matter what application has the top level window.

All suggestions are very welcome!

thanks
 
M

Marcus

I sounds like this would do the same thing as this.Focus(), but I will
give it a shot.

thanks


Stanimir said:
Hi Marcus,

You might want to use a P/Invoke approach. Namely, you can use User32's
SetForegroundWindow() API to give your window focus without having to set
Window State, TopLevel (Did you mean TopMost ?) and other Form properties.

The declartion for the API is:

[System.Runtime.InteropServices.DllImport("User32")]
private static extern bool SetForegroundWindow(
IntPtr hWnd
);

A call to this function can be done in a Form's Load event handler method:

private void Form1_Load(object sender, EventArgs e)
{
SetForegroundWindow(this.Handle);
}

That way your window will be given focus and it will most likely be in front
of any other windows, even if they consume the whole workspace.

--
Stanimir Stoyanov
www.stoyanoff.info


Marcus said:
How do I do it in c#?

My current solution works sometimes, but sometimes the form comes
behind the fullscreen application.

I am using the following in the forms constructor

this.WindowState = FormWindowState.Normal;
this.Focus();
this.BringToFront();
this.TopLevel = true;

All I want to do is to put a message on the screen, and I want it to be
visible no matter what application has the top level window.

All suggestions are very welcome!

thanks
 
M

Marcus

thanks for answering,
I have tried this approach already, but it seems like when I play
applications like "World of Warcraft" which has the topMost (yes I
meant the topMost not the topLevel as I wrote previously) window my
message does not always get displayed in front of WoW's full screen
window.
My application which creates the message window form is always started
before the full screen applications, which could have the negative
effect that the most recently started application trying to claim to be
topmost gets to be.
 

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