How can I start my application as hidden?

Posted on 2007-11-20
Last Modified: 2013-12-17

How may I start my Application with no visible Form. I just want to add A NotifyIcon in the systray. When the user DoubleClick my NotifyIcon, I will execute some code.

Question by:EEssam
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

Assisted Solution

talspaugh27 earned 50 total points
ID: 20322034
Found this on another solution, if this doesnt help let me know and I will shoot off the link to the other solution to ya

static void Main()
    System.ComponentModel.Container components;
    components = new System.ComponentModel.Container();
      System.Windows.Forms.ContextMenu contextMenu;
      contextMenu = new System.Windows.Forms.ContextMenu();

      contextMenu.MenuItems.Add("&Close", new EventHandler(CloseMenuItem_Click));

      System.Windows.Forms.NotifyIcon notifyIcon;
      notifyIcon = new System.Windows.Forms.NotifyIcon(components);
      notifyIcon.Icon = System.Drawing.SystemIcons.Application;
      notifyIcon.ContextMenu = contextMenu;
      notifyIcon.Visible = true;


  static void CloseMenuItem_Click(object sender, EventArgs e)
And then in your application, you can just create new forms whenever you want, based on whatever events are triggered.
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20322052
Traditionally, in your Main method, you use to run a Form to start your application. Use an application context. Have a look to this skeleton:

    static class Program
        public static AppContext Context;
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
            Context = new AppContext();
    // Derive your own ApplicationContext class
    public class AppContext : ApplicationContext
        private NotifyIcon MyNotifyIcon;
        // define other fields for your application
        public AppContext()
            this.ThreadExit += new EventHandler(AppContext_ThreadExit);
        #region Exit events
        void AppContext_ThreadExit(object sender, EventArgs e)
            // some termination tasks
        #region Notify icon events
        private void MenuAbout_Click(object sender, EventArgs e)
            AboutForm form = new AboutForm();
        private void MenuExit_Click(object sender, EventArgs e)
        #region Private methods
        private void InitializeComponents()
            // Creates Notify Icon context menu
            ContextMenuStrip contextMenu = new ContextMenuStrip();
            ToolStripMenuItem MenuAbout = new ToolStripMenuItem("About...");
            ToolStripSeparator Separator1 = new ToolStripSeparator();
            ToolStripMenuItem MenuExit = new ToolStripMenuItem("Exit");
            contextMenu.ShowCheckMargin = true;
            contextMenu.ShowImageMargin = false;
            contextMenu.Size = new System.Drawing.Size(185, 126);
            contextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            MenuAbout.Click += new System.EventHandler(MenuAbout_Click);
            MenuExit.Click += new System.EventHandler(MenuExit_Click);
            NotifyIcon = new NotifyIcon();
            NotifyIcon.ContextMenuStrip = contextMenu;
            NotifyIcon.Icon = new Icon(Assembly.GetExecutingAssembly().GetManifestResourceStream("YourApp.Resources.note.ico"));
            NotifyIcon.Visible = true;

Open in new window


Author Comment

ID: 20322385
Thanks guys but this is a lot of difficult work. I'm sure there are easier ways. I do not want to completely  get rid of the main form. I have several timers on it, contextMenu and notifyIcon... all visually designed and set. I just don't want to visually show the main form.
LVL 22

Expert Comment

ID: 20324763
LVL 55

Accepted Solution

Jaime Olivares earned 450 total points
ID: 20325151
Easiest way is to set the WindowState to FormWindowState.Minimized at design time.
Then implement the Load event and put this.Hide() inside.

Featured Post

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

623 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