locked
Minimize in system tray RRS feed

  • Question

  •  

    Hi,

     

    is there any way that I can make a program that when you minimize it it goes to the system tray instead of the taskbar??? like the windows live messenger??

     

    Thanks,

    Anthony

     

    Tuesday, September 4, 2007 1:38 PM

Answers

  • Here it is:

    First the notify icon code (add it to the InitializeComponent method):


    Code Snippet

      private System.Windows.Forms.NotifyIcon notifyIcon1;
                this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
                //
                // notifyIcon1
                //
                this.notifyIcon1.BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info;
                this.notifyIcon1.BalloonTipText = "Application info";
                this.notifyIcon1.BalloonTipTitle = "Application";
                this.notifyIcon1.Text = "Application info";
                this.notifyIcon1.Visible = true;


    Captura the form resize event (InitializeComponent method):


               
    Code Snippet

    this.Resize += new System.EventHandler(this.Form1_Resize);


    And add the code in the event handler


              
    Code Snippet

      if (this.WindowState == FormWindowState.Minimized)
                    this.Hide();


    With this code you hide the form. If you want to show it you have to capture the doubleclick event of the notifyIcon (for example) and you the form and reset the WindowState to FormWindowState.Normal.

    Lluís Montero
    http://www.portal-seo.com

    Tuesday, September 4, 2007 2:09 PM

All replies

  • Hi,

    you have to add a NotifyIcon control to your form to enable the system tray icon. To make the aplication disapear yau have to call the hide method or put the visible property to false.

    Lluís Montero
    http://www.portal-seo.com
    Tuesday, September 4, 2007 1:54 PM
  •  

    Thanks for your answer, but I don't know exactly how to do that...I am a java programmer and I have just started programming in C#...so can you give me some example code of how to do this??
    Tuesday, September 4, 2007 1:57 PM
  • Here it is:

    First the notify icon code (add it to the InitializeComponent method):


    Code Snippet

      private System.Windows.Forms.NotifyIcon notifyIcon1;
                this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
                //
                // notifyIcon1
                //
                this.notifyIcon1.BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info;
                this.notifyIcon1.BalloonTipText = "Application info";
                this.notifyIcon1.BalloonTipTitle = "Application";
                this.notifyIcon1.Text = "Application info";
                this.notifyIcon1.Visible = true;


    Captura the form resize event (InitializeComponent method):


               
    Code Snippet

    this.Resize += new System.EventHandler(this.Form1_Resize);


    And add the code in the event handler


              
    Code Snippet

      if (this.WindowState == FormWindowState.Minimized)
                    this.Hide();


    With this code you hide the form. If you want to show it you have to capture the doubleclick event of the notifyIcon (for example) and you the form and reset the WindowState to FormWindowState.Normal.

    Lluís Montero
    http://www.portal-seo.com

    Tuesday, September 4, 2007 2:09 PM
  • Thanks,

    I made it...you was really helpfull...

    Thanks a lot again,

    Anthony

    Tuesday, September 4, 2007 2:28 PM