Solved

Make my program in System Tray with C#

Posted on 2004-09-13
5
244 Views
Last Modified: 2010-08-05
I want to write my program but use it from the system tray . I don't kow how to make that system tray part. I also want to know how to make a right click menu on that system tray icon.
0
Comment
Question by:drtoto82
5 Comments
 
LVL 19

Accepted Solution

by:
Desp earned 43 total points
ID: 12051410
0
 
LVL 5

Assisted Solution

by:tzxie2000
tzxie2000 earned 41 total points
ID: 12052514
put an notifyicon on the form

put an contextmenu on the form and design your menu

assign notifyicon.contextmenu to the contextmenu you add

all is done
0
 

Assisted Solution

by:happy_coder
happy_coder earned 41 total points
ID: 12056118
here is the code needed to make a notifyicon and the context menu needed for it

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication4
{
      /// <summary>
      /// Summary description for Form1.
      /// </summary>
      public class Form1 : System.Windows.Forms.Form
      {
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.Container components = null;

            
            private NotifyIcon notifyIcon;

            
            private MenuItem menuItem;

            
            private ContextMenu contextMenu;


            public Form1()
            {
                  //
                  // Required for Windows Form Designer support
                  //
                  InitializeComponent();

                  //
                  // TODO: Add any constructor code after InitializeComponent call
                  //
            }

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if (components != null)
                        {
                              components.Dispose();
                        }
                  }
                  base.Dispose( disposing );
            }

            #region Windows Form Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                  //
                  // Form1
                  //
                  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                  this.ClientSize = new System.Drawing.Size(292, 266);
                  this.Name = "Form1";
                  this.Text = "Form1";
                  this.Load += new System.EventHandler(this.Form1_Load);

            }
            #endregion

            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                  Application.Run(new Form1());
            }

            private void Form1_Load(object sender, System.EventArgs e)
            {
                  menuItem = new MenuItem();
                  contextMenu = new ContextMenu();
                  notifyIcon = new NotifyIcon();

                  menuItem.Index = 0;
                  menuItem.Text = "E&xit";
                  menuItem.Click += new EventHandler(menuItem_Click);

                   contextMenu.MenuItems.Add(menuItem);

                  notifyIcon.Icon = new Icon("app.ico");

                  notifyIcon.ContextMenu = contextMenu;

                  notifyIcon.DoubleClick += new EventHandler(notifyIcon_DoubleClick);

                  notifyIcon.Visible = true;

            }
            
            private void Exit_OnClick()
            {
                  Application.Exit();
            }
            
            private void menuItem_Click(object sender, EventArgs e)
            {
                  Application.Exit();
            }
            
            private void notifyIcon_DoubleClick(Object Sender, EventArgs e)
            {
                  
                  if (this.WindowState == FormWindowState.Minimized)
                        this.WindowState = FormWindowState.Normal;
   
                  this.Activate();
            }


      }
}
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question