Tray Icon
-
When i minimize my application then i want it to hide as i have a tray icon and then i can open it from there But i am not able to catch form's Minimize button event How can i minimize the form(hide)
Public Class MinimizeInTray Public TrayMenu As New ContextMenu Public Restorewindowstate As FormWindowState = FormWindowState.Normal Public trayicon As New NotifyIcon Public mainform As New Form Public visible As Boolean = False Sub New(ByVal form As Form, Optional ByVal icontext As String = "", Optional ByVal icon As Icon = Nothing) TrayMenu.MenuItems.Clear() mainform = form TrayMenu.MenuItems.Add("Restore", AddressOf restore) TrayMenu.MenuItems.Add("Close", AddressOf close) AddHandler trayicon.DoubleClick, AddressOf restore With trayicon .Visible = False If IsNothing(icon) Then .Icon = mainform.Icon Else .Icon = icon End If .Text = icontext .ContextMenu = TrayMenu End With End Sub Private Sub restore(ByVal sender As System.Object, ByVal e As System.EventArgs) mainform.ShowInTaskbar = True visible = True trayicon.Visible = False mainform.WindowState = Restorewindowstate End Sub Private Sub close(ByVal sender As System.Object, ByVal e As System.EventArgs) trayicon.Visible = False mainform.Close() End Sub End Class
-
Public Class MinimizeInTray Public TrayMenu As New ContextMenu Public Restorewindowstate As FormWindowState = FormWindowState.Normal Public trayicon As New NotifyIcon Public mainform As New Form Public visible As Boolean = False Sub New(ByVal form As Form, Optional ByVal icontext As String = "", Optional ByVal icon As Icon = Nothing) TrayMenu.MenuItems.Clear() mainform = form TrayMenu.MenuItems.Add("Restore", AddressOf restore) TrayMenu.MenuItems.Add("Close", AddressOf close) AddHandler trayicon.DoubleClick, AddressOf restore With trayicon .Visible = False If IsNothing(icon) Then .Icon = mainform.Icon Else .Icon = icon End If .Text = icontext .ContextMenu = TrayMenu End With End Sub Private Sub restore(ByVal sender As System.Object, ByVal e As System.EventArgs) mainform.ShowInTaskbar = True visible = True trayicon.Visible = False mainform.WindowState = Restorewindowstate End Sub Private Sub close(ByVal sender As System.Object, ByVal e As System.EventArgs) trayicon.Visible = False mainform.Close() End Sub End Class
-
Thanks for the code but what i want is something like outlook. if i minimize my form then it should not be visible. Not only minimize from tray icon but also from minimize button of the form to.
I think same code should work . just add a button to the form which indiacates the minimize sign. and put the code on that i same send.
-
When i minimize my application then i want it to hide as i have a tray icon and then i can open it from there But i am not able to catch form's Minimize button event How can i minimize the form(hide)
-
Thanks for the code but what i want is something like outlook. if i minimize my form then it should not be visible. Not only minimize from tray icon but also from minimize button of the form to.
write your code on form_resize event check for form.windowstate = FormWindowState.Minimized and write your code to hide your form and show systemtray icon
Vilsad P P MCTS (Windows Applications) .Net 2.0
-
Here is an article I wrote on this subject including balloon tips. http://www.codeproject.com/dotnet/notifyiconcontrol20.asp[^] Hope that helps. Ben
Thank You Sir, It is very nice and useful Article.