# VBForums CodeBank > CodeBank - Visual Basic .NET >  VB.NET - notifyIcon .

## Pirate

How to put icon in the system tray when you click "X" button on your form .

----------


## jstansell

Thanks Pirate!  I have one question, I have the need to change the icon based on the status of the app.  How do I change the icon progammatically?  That property does not have the "FromFile" method like an image property.

Thanks again for the code.

----------


## dynamic_sysop

like this ....

VB Code:
Dim ico As New Icon("C:\someicon.ico") '/// path of your icon.
        ni.Icon = ico '/// set the icon to your notify icon ( where your notify icon's name would be inplace of ni )

----------


## Pirate

> _Originally posted by jstansell_ 
> *Thanks Pirate!  I have one question, I have the need to change the icon based on the status of the app.  How do I change the icon progammatically?  That property does not have the "FromFile" method like an image property.
> Thanks again for the code.*


dynamic_sysop got your back . :Wink:

----------


## jstansell

That worked.  Thanks for you help!! :Big Grin:

----------


## flycast

Pirate:
Thanks for the example. Is there a way that you can see that I could do the same thing using the minimize thingie (technical term) two elements to the left of the X box?

Also, is the only way to kill this app from the task list?

Thanks,
Eric

----------


## Codehammer

Note, Editing the Forms Closing Event Will to Minimize will cause this to Fire when a Shutdown or Forceshutdown is executed, meaning your computer wont Shutdown until the App is Closed by a Application.exit somewhere else.

----------


## technicalItch

Thats very good.  Is there any way it could be adapted for a .aspx vb.net page?  When the user clicks the X on their browser it has the same effect?

----------


## Pirate

> Thats very good.  Is there any way it could be adapted for a .aspx vb.net page?  When the user clicks the X on their browser it has the same effect?


Not without client-side script,I believe.

----------


## polecat

Hi flycast

I use this to handle minimize and left click as i have context menu on the 
right click


VB Code:
Private Sub mainForm_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        If Me.WindowState = FormWindowState.Minimized Then
            NotifyIcon1.Visible = True
            Me.Visible = False
        End If
    End Sub
      Private Sub NotifyIcon1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            Me.Visible = True
            If Me.WindowState = FormWindowState.Minimized Then
                Me.WindowState = FormWindowState.Normal
            End If
            NotifyIcon1.Visible = False
        End If
    End Sub

Hope you dont mind me putting this here !

----------


## Pirate

That's alright dude...This thread is almost 3 years old  :Wink:

----------

