[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Make my program in System Tray with C#

Posted on 2004-09-13
5
Medium Priority
?
256 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
3 Comments
 
LVL 19

Accepted Solution

by:
Fahad Mukhtar earned 172 total points
ID: 12051410
0
 
LVL 5

Assisted Solution

by:tzxie2000
tzxie2000 earned 164 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 164 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Introduction to Processes
Screencast - Getting to Know the Pipeline

834 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