C # Creating a program that runs in the background?

Possible duplicate:
What is the correct way to minimize a tray to a C # WinForms application?

How can I create a program that runs in the background, and can be accessed through Windows, the “Notification Area” (if the date and time are in the lower right corner)?

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

+4
source share
1 answer
  • Drag a NotifyIcon and ContextMenuStrip .
  • Set the "NotifyIcon" context menu to the one you added.
  • Add 2 menu items (e.g. Restore, Exit)
  • Set the resize form event and run 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; } 

This project can be downloaded as an example.

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

+3
source

Source: https://habr.com/ru/post/1310914/


All Articles