Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BringToFront() in C#

Tags:

c#

.net

winforms

I have an app here I made for a client, but sometimes he doesn't know if an order has arrived because he plays World Of Warcraft with the volume max'd out. But he said he wants my little notification window to appear on top of his game if a new order arrives.

So, I was thinking I could just use BringToFront(); which seems to work when full-screen apps are Maximized. But, I have noticed that while playing V8 Supercars in full screen, BringToFront(); doesn't bring the notification window on top of the game, so I figure that some games have another way of making sure they remain on top of everything else.

How can I make sure that whenever I need my form to be seen, it will always show up on top of anything else?

like image 787
bendr Avatar asked Jun 10 '11 07:06

bendr


3 Answers

form.TopMost = true;
form.ShowDialog();
form.BringToFront();

Should work with all applications, full-screen exclusive games included (tested on all my games, so far, it works).

like image 147
user703016 Avatar answered Nov 18 '22 12:11

user703016


You could try setting the notification form's TopMost property to true...or make it modal by calling .ShowDialog instead of .Show.

like image 36
alexD Avatar answered Nov 18 '22 13:11

alexD


I struggled with the same topic, especially when a "link" to a custom protocol was clicked in Outlook. (The App catched it, but always in the background...)

Even though a lot of solutions worked while debugging, for the "Live-Deployment" only the following chain of calls seems to achieve what was desired:

(Invoked, cause handling of links happens from a thread)

this.Invoke(new Action(() => {
  this.Activate();
  //...do stuff
  this.TopMost = true;
  this.BringToFront();
  this.TopMost = false;                              
}));

Works about every time.

like image 4
dognose Avatar answered Nov 18 '22 14:11

dognose