Minimize to System Tray Problem

Reapz

Regular
Joined
Dec 15, 2002
Messages
74
Hi guys,

I got my app' to minimize to the tray ok that was easy enuff and I've got a doubleclick event for the trayicon to restore the form using windowstate.normal and this was all working fine.

Now I've added a couple of lines of code so that when the form is open form1.showintaskbar = true and trayicon.visible = false and then when the form gets minimized form1.showintaskbar = false and trayicon.visible = true.

The problem I'm having since I made these changes is that double clicking on the trayicon restores the app' but only to the taskbar and assumes that as being its 'normal' state. The only way I can see the form after that is to maximize it.

Can't find anything about this specific prob' on the forums or on the MSDN examples or the Forms FAQ.

Anyway here's the code...

Visual Basic:
Private Sub TrayIcon_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrayIcon.DoubleClick
        Me.ShowInTaskbar = True
        TrayIcon.Visible = False
        Me.WindowState = FormWindowState.Normal
        Me.Activate()
End Sub

Private Sub Form1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        If Me.WindowState = FormWindowState.Minimized Then
            Me.ShowInTaskbar = False
            TrayIcon.Visible = True
        End If
End Sub

Cheers,
Andy!
 
Just set Visible = False when you minimize it, and Visible = True when you maximize it.
 
i thing .show() and .hide() are faster, than .visible = treu, hide/show is less code and look nicer, but that personal opinion i gess
 
I don't see how one can be faster than the other... all either of them do is remove WS_VISIBLE from the list of window styles applied to the form.
 
Aah I see... no need for the showintaskbar at all. That will teach me to try and be clever :D.

Cheers VF!
 
TrayIcon is now called NotifyIcon.

There is actually a subtleish difference between the ShowInTaskbar and Visible methods. If you set Visible to false, then, when you Alt+Tab between applications, your application will not be in the list. With the ShowInTaskbar method, your application will still be there (although it turns out to be a "blank window" icon -- this seems like a bug...?).

I didn't have a problem with either method, though: you just have to make sure to reset the rest of the state (make it visible or whatever) before resizing the form.
 
Hi guys,

i have a problem,

I have written the code exactly the same which you have posted.
the following is the ccode,

Private Sub Form1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Resize
If Me.WindowState = FormWindowState.Minimized Then
Me.Hide()
'Me.ShowInTaskbar = False
TrayIcon.Visible = True
TrayIcon.Text = "Hide Me"
End If
End Sub

Private Sub TrayIcon_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TrayIcon.MouseDoubleClick

Me.ShowInTaskbar = True
Me.Show()
TrayIcon.Text = "Show Me"
Me.Enabled = True
Me.WindowState = FormWindowState.Normal
*******'Me.Activate()*****

End Sub


The Problem is i do not know where the activate method is there for the form.
and when i minimize the form, it is perfectly getting invisible and as well as from the taskbar too.

but i cannot see the icon in the System Tray. please help.

Thanks
Vish
 
Back
Top