minimizing application to tray

add a notify icon control to your form and be sure to set it to visible. now you can use the Location changed event to hide the form and use the NotifyIcon's click or Double-Click event to re-show the form

There are numerous ways of doing this
 
You also have to set ShowInTaskbar to False when minimized.
 
Have you set an Icon for the NotifyIcon component?
 
thanks u were right I hadnt set the nofify icon's icon I had set the form icon and thought it would work.
But the onclick event doesnt work see my code:
VB.NET:
Public Class Form1
    Private Sub Form1_LocationChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LocationChanged
        Me.Hide()
    End Sub

    Private Sub NotifyIcon1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.Click
        Me.Show()
    End Sub
End Class

This does dissapear on minimising but when i click the icon in the system tray once then the form just shows in the taskbar as minimized and when i click again then it become maximized
do I have to set the form maximised function on click of the notify icon?
 
ok nevermind i fixed that with
VB.NET:
Public Class Form1
    Private Sub Form1_LocationChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LocationChanged
        If Me.WindowState = FormWindowState.Minimized Then
            Me.Hide()
        End If
    End Sub

    Private Sub NotifyIcon1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.Click
        Me.WindowState = FormWindowState.Maximized
        Me.Show()
        Me.Focus()
    End Sub
End Class
But the when maximised the form is still not in focus(above all other windows)
 
I found this note about the Focus method:
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.
So you use the Activate method.
 
Back
Top