[RESOLVED] Click on NotifyIcon, bring my program to front
Hello,
I have a Notify Icon on the main form of my application. It periodically checks for Alerts (as we call them) and notifies the user if they have new Alerts (very similar to Outlook telling you that you have a new e-mail). When the user clicks on the Notify Icon, it brings the Alerts module to the front if an instance of it is open, and opens a new instance if there is not one.
But, I would also like for my program to come to the front as if the user clicked on it in the taskbar.
Does this require some sort of API call?
I have tried these:
Me.WindowState = FormWindowState.Normal
Me.Focus()
Me.BringToFront()
but none have worked.
Any ideas?
Thanks
Re: Click on NotifyIcon, bring my program to front
You may want to concider using the BringWindowToTop API function
Re: Click on NotifyIcon, bring my program to front
Thanks for the idea, I bet this is the right track.
I put this at the top of my class:
Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As IntPtr) As IntPtr
and then I call this:
BringWindowToTop(Me.Handle)
but nothing is happening. I have used APIs very little. Am I missing something important here?
Re: Click on NotifyIcon, bring my program to front
This works for me
Code:
Private Sub NotifyIcon1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.Click
Me.Visible = True
Me.WindowState = FormWindowState.Normal
Me.ShowInTaskbar = True
Me.NotifyIcon1.Visible = False
End Sub
Re: Click on NotifyIcon, bring my program to front
Excuse me, its a balloon click. So, I'm not looking to do the standard Maximize Form/Make Notify Icon Invisible thing. The program is in the taskbar, and the notify icon is always visible. A balloon pops up if the user gets a new alert, and when they click it I want my application to pop up front. This is what happens when I run this (see attached pic):
Quote:
Me.WindowState = FormWindowState.Normal
BringWindowToTop(Me.Handle)
This happens when I position Windows Explorer over the form to where I can still see this top and then click the balloon. Notice how it appears selected, but it is still behind Windows Explorer. Is this because I am running it in the debugger?
Re: Click on NotifyIcon, bring my program to front
I guess this should really be moved to the API forum now. Moderators? Anyone? I would appreciate it.
Re: Click on NotifyIcon, bring my program to front
Re: Click on NotifyIcon, bring my program to front
This not an API question. Just call the form's Activate method. If you tried those methods and they didn't work then you should have read their MSDN help topics to see if you were using them incorrectly. If you'd done that for the Focus method then you'd have seen this:
Quote:
Focus is a low-level method intended primarily for custom control authors. Instead, application programmers should use the Select method or the ActiveControl property for child controls, or the Activate method for forms.
If we as developers cannot read help documentation then there is no hope for our users.
Re: Click on NotifyIcon, bring my program to front
RobDog888, thanks for the move.
jmcilhinney - sorry, I know how much you talk about the MSDN help topics. And I agree with what you say about reading help documentation. Thanks for the help, that worked perfectly, by the way.
Thanks again, everyone.