Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Creating A Program That Runs In The Background? [duplicate]

Tags:

c#

winforms

Possible Duplicate:
What's the proper way to minimize to tray a C# WinForms app?

How can I create a program that runs in the background, and can be accessed via the Windows' "Notification Area" (Where the date and time are in the lower right hand corner)?

In other words, I want to be able to create a program that runs and can toggle between having a display window and not having a display window.

like image 245
sooprise Avatar asked May 25 '10 22:05

sooprise


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

What is C in coding language?

C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

Why was C written?

The C language was actually created to move the UNIX kernel code from assembly to a higher level language, which would do the same tasks with fewer lines of code. Oracle database development started in 1977, and its code was rewritten from assembly to C in 1983. It became one of the most popular databases in the world.


1 Answers

  1. Drag and drop a NotifyIcon and a ContextMenuStrip.
  2. Set de NotifyIcon's context menu to the one you added
  3. Add 2 menuitems (e.g. Restore, Exit)
  4. Set the Form event resize and do the following check

    private void MyForm_Resize(object sender, EventArgs e)
    {
        if (this.WindowState == FormWindowState.Minimized) this.Hide();
        else this.Show();
    }
    
    // you could also restore the window with a
    // double click on the notify icon
    private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        this.Show();
        this.WindowState = FormWindowState.Normal;
    }
    

For a example can download this project

Don't worry about the right click event, the NotifyIcon will automatically detect it and show the ContextMenu

like image 172
BrunoLM Avatar answered Sep 28 '22 12:09

BrunoLM