Solved

Make my program in System Tray with C#

Posted on 2004-09-13
5
239 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
Comment Utility
0
 
LVL 5

Assisted Solution

by:tzxie2000
tzxie2000 earned 41 total points
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article will show, step by step, how to integrate R code into a R Sweave document
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 …

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now