Solved

Make my program in System Tray with C#

Posted on 2004-09-13
5
246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
A short article about problems I had with the new location API and permissions in Marshmallow
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 …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

688 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