Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Minimize to system tray

Minimize to system tray

Scheduled Pinned Locked Moved C#
csharpquestion
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    devvvy
    wrote on last edited by
    #1

    Hi, how do you minimize your app to system tray in C#/.NET? norm

    A J 2 Replies Last reply
    0
    • D devvvy

      Hi, how do you minimize your app to system tray in C#/.NET? norm

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      Add a NotifyIcon to your form and assign it an icon. set visible = false if you do not want it to be there all the time. In the event handler where you want the app to minimize to the tray do something like: private void btn_MinimiseToTray_Click(object sender, System.EventArgs e) { this.WindowState = FormWindowState.Minimized; this.ShowInTaskbar = false; this.notifyIcon1.Visible = true; } and reverse it all when the icon is clicked or on a context menu etc....

      D 1 Reply Last reply
      0
      • A Anonymous

        Add a NotifyIcon to your form and assign it an icon. set visible = false if you do not want it to be there all the time. In the event handler where you want the app to minimize to the tray do something like: private void btn_MinimiseToTray_Click(object sender, System.EventArgs e) { this.WindowState = FormWindowState.Minimized; this.ShowInTaskbar = false; this.notifyIcon1.Visible = true; } and reverse it all when the icon is clicked or on a context menu etc....

        D Offline
        D Offline
        devvvy
        wrote on last edited by
        #3

        Thanks! I successfully send the app to system tray. But I am having some trouble trying to restore it from the tray. private void NotifyIcon_Clicked(object sender, System.EventArgs e) { //None of this help, the form just disappeared, never to come back. WindowState=FormWindowState.Normal; ShowInTaskbar=true; BringToFront(); Focus(); Visible=true; return; } I just need one more tip for this. norm

        G 1 Reply Last reply
        0
        • D devvvy

          Thanks! I successfully send the app to system tray. But I am having some trouble trying to restore it from the tray. private void NotifyIcon_Clicked(object sender, System.EventArgs e) { //None of this help, the form just disappeared, never to come back. WindowState=FormWindowState.Normal; ShowInTaskbar=true; BringToFront(); Focus(); Visible=true; return; } I just need one more tip for this. norm

          G Offline
          G Offline
          Guillermo Rivero
          wrote on last edited by
          #4

          did you try Activate() ? Free your mind...

          D 2 Replies Last reply
          0
          • G Guillermo Rivero

            did you try Activate() ? Free your mind...

            D Offline
            D Offline
            devvvy
            wrote on last edited by
            #5

            Thanks. But, yes I did. Activate didn't work :zzz: norm

            1 Reply Last reply
            0
            • G Guillermo Rivero

              did you try Activate() ? Free your mind...

              D Offline
              D Offline
              devvvy
              wrote on last edited by
              #6

              Hi Guillermo, I've got it working - well, the title bar didn't get repainted properly. Part/Chunk of it (Titlebar) appears dark. I called Invalidate(), which got rid of the problem in client area, not the title bar... private void NotifyIcon_Clicked(object sender, System.EventArgs e) { WindowState=FormWindowState.Normal; ShowInTaskbar=true; BringToFront(); Focus(); Visible=true; ClientSize = new System.Drawing.Size(292, 318); Location = formLocation; Invalidate(); return; } private void Form_Clicked(object sender, System.EventArgs e) { formLocation = this.Location; WindowState = FormWindowState.Minimized; ShowInTaskbar = false; notifyIcon.Visible = true; return; } norm

              G 1 Reply Last reply
              0
              • D devvvy

                Hi Guillermo, I've got it working - well, the title bar didn't get repainted properly. Part/Chunk of it (Titlebar) appears dark. I called Invalidate(), which got rid of the problem in client area, not the title bar... private void NotifyIcon_Clicked(object sender, System.EventArgs e) { WindowState=FormWindowState.Normal; ShowInTaskbar=true; BringToFront(); Focus(); Visible=true; ClientSize = new System.Drawing.Size(292, 318); Location = formLocation; Invalidate(); return; } private void Form_Clicked(object sender, System.EventArgs e) { formLocation = this.Location; WindowState = FormWindowState.Minimized; ShowInTaskbar = false; notifyIcon.Visible = true; return; } norm

                G Offline
                G Offline
                Guillermo Rivero
                wrote on last edited by
                #7

                Good. When I did it, I used Form.Hide() instead of changing the windowstate, so I didn't have the problem of repainting. When I clicked on the taskbar icon, I used Form.Show(). In that way, it did good for me.. Free your mind...

                D 1 Reply Last reply
                0
                • G Guillermo Rivero

                  Good. When I did it, I used Form.Hide() instead of changing the windowstate, so I didn't have the problem of repainting. When I clicked on the taskbar icon, I used Form.Show(). In that way, it did good for me.. Free your mind...

                  D Offline
                  D Offline
                  devvvy
                  wrote on last edited by
                  #8

                  Thanks, it's working just fine now. I hide the form, as supposed to minimizing it. norm

                  1 Reply Last reply
                  0
                  • D devvvy

                    Hi, how do you minimize your app to system tray in C#/.NET? norm

                    J Offline
                    J Offline
                    JJF007
                    wrote on last edited by
                    #9

                    What i am doing is to generate a TrayIcon and use this code: // Public Bool for Closing the app bool boolAlowClose = false; // Press the closing Button at the app protected void frmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (!boolAlowClose) { this.m_notifyicon.Visible = true; this.Hide(); e.Cancel = true; } else { e.Cancel = false; } } // ContextMenu from Trayicon to view the app again private void cmnu_View_Form_Click(object sender, System.EventArgs e) { this.m_notifyicon.Visible = false; this.Show(); } // This is the Menu "Close" hat close the application private void cmnu_Menu_Close_Click(object sender, System.EventArgs e) { boolAlowClose = true; this.Close(); } Hope this will help! Matthias

                    D 1 Reply Last reply
                    0
                    • J JJF007

                      What i am doing is to generate a TrayIcon and use this code: // Public Bool for Closing the app bool boolAlowClose = false; // Press the closing Button at the app protected void frmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (!boolAlowClose) { this.m_notifyicon.Visible = true; this.Hide(); e.Cancel = true; } else { e.Cancel = false; } } // ContextMenu from Trayicon to view the app again private void cmnu_View_Form_Click(object sender, System.EventArgs e) { this.m_notifyicon.Visible = false; this.Show(); } // This is the Menu "Close" hat close the application private void cmnu_Menu_Close_Click(object sender, System.EventArgs e) { boolAlowClose = true; this.Close(); } Hope this will help! Matthias

                      D Offline
                      D Offline
                      devvvy
                      wrote on last edited by
                      #10

                      got it, thanks. norm

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups