How to put an .net application in system tray when minimized?

Add a NotifyIcon control to your form, then use the following code.

Add a NotifyIcon control to your form, then use the following code: private void frm_main_Resize(object sender, EventArgs e) { if (this. WindowState == FormWindowState. Minimized) { this.

ShowInTaskbar = false; this. Visible = true; } } private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) { this.Show(); this. WindowState = FormWindowState.

Normal; this. ShowInTaskbar = true; notifyIcon1. Visible = false; } You may not need to set the ShowInTaskbar property.

Your sample is grossly incomplete. – FlySwat Sep 16 '08 at 19:41 Can you elaborate? – Phillip Wells Sep 16 '08 at 19:45 Your missing the declarations from the form, the notifyIcon control, and your missing the overridden dispose method :) – FlySwat Sep 16 '08 at 19:49 Though I noticed you edited, and added some instructions, so ignore my critique :) – FlySwat Sep 16 '08 at 19:50 To the point.

I got what I need thanks Phillip. – bugBurger Sep 16 '08 at 19:53.

You can leverage a built in control called NotifyIcon. This creates a tray icon when shown. @Phillip has a code example that is somewhat complete.

There is a gotcha though: You must override your applications main form Dispose method to call Dispose on NotifyIcon, otherwise it will stay in your tray after application exits. Public void Form_Dispose(object sender, EventArgs e) { if (this. Disposing) notifyIcon1.Dispose(); } Something like that.

Thanks for missing part. – bugBurger Sep 16 '08 at 19:53 1 This shouldn't be necessary if you put the notify icon on the form using the designer - the VS-generated Dispose() will call components.Dispose() which should dispose all components which were created with it as a container. – Jesse C.

Slicer Sep 17 '08 at 15:51.

I did a little searching, maybe this will help: developer.com/net/csharp/article.php/333....

You can do this by adding a NotifyIcon to your form and handling the form's resize event. To get back from the tray handle the NotifyIcon's double-click event. If you want to add a little animation you can do this too... 1) Add the following module: Module AnimatedMinimizeToTray Structure RECT Public left As Integer Public top As Integer Public right As Integer Public bottom As Integer End Structure Structure APPBARDATA Public cbSize As Integer Public hWnd As IntPtr Public uCallbackMessage As Integer Public uEdge As ABEdge Public rc As RECT Public lParam As IntPtr End Structure Enum ABMsg ABM_NEW = 0 ABM_REMOVE = 1 ABM_QUERYPOS = 2 ABM_SETPOS = 3 ABM_GETSTATE = 4 ABM_GETTASKBARPOS = 5 ABM_ACTIVATE = 6 ABM_GETAUTOHIDEBAR = 7 ABM_SETAUTOHIDEBAR = 8 ABM_WINDOWPOSCHANGED = 9 ABM_SETSTATE = 10 End Enum Enum ABNotify ABN_STATECHANGE = 0 ABN_POSCHANGED ABN_FULLSCREENAPP ABN_WINDOWARRANGE End Enum Enum ABEdge ABE_LEFT = 0 ABE_TOP ABE_RIGHT ABE_BOTTOM End Enum Public Declare Function SHAppBarMessage Lib "shell32.

Dll" Alias "SHAppBarMessage" (ByVal dwMessage As Integer, ByRef pData As APPBARDATA) As Integer Public Const ABM_GETTASKBARPOS As Integer = &H5& Public Const WM_SYSCOMMAND As Integer = &H112 Public Const SC_MINIMIZE As Integer = &HF020 Public Sub AnimateWindow(ByVal ToTray As Boolean, ByRef frm As Form, ByRef icon As NotifyIcon) ' get the screen dimensions Dim screenRect As Rectangle = Screen. GetBounds(frm. Location) ' figure out where the taskbar is (and consequently the tray) Dim destPoint As Point Dim BarData As APPBARDATA BarData.

CbSize = System.Runtime.InteropServices.Marshal. SizeOf(BarData) SHAppBarMessage(ABMsg. ABM_GETTASKBARPOS, BarData) Select Case BarData.

UEdge Case ABEdge. ABE_BOTTOM, ABEdge. ABE_RIGHT ' Tray is to the Bottom Right destPoint = New Point(screenRect.

Width, screenRect. Height) Case ABEdge. ABE_LEFT ' Tray is to the Bottom Left destPoint = New Point(0, screenRect.

Height) Case ABEdge. ABE_TOP ' Tray is to the Top Right destPoint = New Point(screenRect. Width, 0) End Select ' setup our loop based on the direction Dim a, b, s As Single If ToTray Then a = 0 be = 1 s = 0.05 Else a = 1 be = 0 s = -0.05 End If ' "animate" the window Dim curPoint As Point, curSize As Size Dim startPoint As Point = frm.

Location Dim dWidth As Integer = destPoint. X - startPoint. X Dim dHeight As Integer = destPoint.

Y - startPoint. Y Dim startWidth As Integer = frm. Width Dim startHeight As Integer = frm.

Height Dim I As Single For I = a To be Step s curPoint = New Point(startPoint. X + I * dWidth, startPoint. Y + I * dHeight) curSize = New Size((1 - i) * startWidth, (1 - i) * startHeight) ControlPaint.

DrawReversibleFrame(New Rectangle(curPoint, curSize), frm. BackColor, FrameStyle. Thick) System.Threading.Thread.

Sleep(15) ControlPaint. DrawReversibleFrame(New Rectangle(curPoint, curSize), frm. BackColor, FrameStyle.

Thick) Next If ToTray Then ' hide the form and show the notifyicon frm. Visible = True Else ' hide the notifyicon and show the form icon. Visible = False frm.Show() End If End Sub End Module 2) Add a NotifyIcon to your form an add the following: Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.

Message) If m. Msg = WM_SYSCOMMAND AndAlso m.WParam. ToInt32() = SC_MINIMIZE Then AnimateWindow(True, Me, NotifyIcon1) Exit Sub End If MyBase.

WndProc(m) End Sub Private Sub NotifyIcon1_DoubleClick(ByVal sender As Object, ByVal e As System. EventArgs) Handles NotifyIcon1. DoubleClick AnimateWindow(False, Me, NotifyIcon1) End Sub.

Here is a very simple method to do this and much more with NotifyIcon using project settings. More here: code.msdn.microsoft.com/TheNotifyIconExa....

You can leverage a built in control called NotifyIcon. This creates a tray icon when shown. @Phillip has a code example that is somewhat complete.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions