• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 184
  • Last Modified:

Set active window when clicking system tray icon

This is very likely to be a simple problem, but from my perspective it's just one of those very irritating imperfections in my program that I can't solve without help.

I have a program that uses a system tray icon and a double click method on the icon to toggle the form's visibility. My problem is when the window becomes inactive and then is hidden, making it visible again annoyingly makes the window appear at the back. I would very much like the window to be set as the topmost active window everytime it is made visible again.
0
alwaysunderestimated
Asked:
alwaysunderestimated
  • 2
1 Solution
 
fluglashCommented:
use API SetForegroundWindow(hWnd as long) as Long
0
 
jmfairchildCommented:
If you didn't want to use an API call, couldn't you just use the SetFocus method on the window?:

Form1.Visible = True
Form1.SetFocus

Also, is there a window that is set to "Always be on top"? (so that it receives focus no matter what other windows/forms are made visible/activated)?

- Jim
0
 
alwaysunderestimatedAuthor Commented:
Thanks Guys,

Both of the comments were very helpful but since I did actually use jmfairchild's suggestion I've accepted his answer. Although for some strange reason I did try using Me.SetFocus before and it didn't seem to make any difference, but now I am using it directly after the Me.Visible = True and it's working exactly as I wanted.

Thanks again
0
 
alwaysunderestimatedAuthor Commented:
I'm not sure if there is a circumstance when Me.SetFocus doesn't work, but I did try using it before and if I recall correctly I had some kind of improper use error - but based on your suggestion I have my program working as I wanted - so thank you.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now