简体   繁体   中英

Gaining focus in a win forms app?

I feel like I'm commiting a cardinal sin by asking how to do this becuase in most instances it would be wrong and evil. But...

I have a winforms app that minimises to the systray when not being used I want to make it pop up and be the topmost window when it recieves a message from a server.

I can make it appear, but I can't get it to be the topmost window. (Setting topmost doesn't change it, but it does make it topmost once it's gained focus)

Does anyone know how to do this?, I wouldn't normally do this but a client has asked for this behavious so I have to implement it... :(

If .Net's 'topmost' thing is not working, you may try getting this service directly from the 'SetWindowPos()' API of Windows. See this page for details.

There is a post around this issue on Microsoft's forums.

Normally, if the window is in your app, calling its BringToFront method should do the trick.

So normal order of operations:

  1. make it visible
  2. call BringToFront()
  3. Set it TopMost

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM