By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,160 Members | 1,323 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,160 IT Pros & Developers. It's quick & easy.

show a windows form in front of an arbitrary fullscreen application

P: n/a
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

May 17 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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.
--
HTH
Stoitcho Goutsev (100)

"Marcus" <ma************@koping.net> wrote in message
news:11*********************@y43g2000cwc.googlegro ups.com... 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

May 17 '06 #2

P: n/a
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" wrote:
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

May 17 '06 #3

P: n/a
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" <admin{at}stoyanoff{dot}info> wrote in message
news:5F**********************************@microsof t.com...
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" wrote:
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

May 17 '06 #4

P: n/a
Stanimir,

It is better to use .NET tools for bring Form on foreground using

Form.Activate()

Regards,
Galin Iliev[MCSD.NET]
www.galcho.com

May 17 '06 #5

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

thanks
Stanimir Stoyanov wrote:
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" wrote:
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


May 18 '06 #6

P: n/a
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.

May 18 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.