C # Writing the Windows application minimizing the system tray

xiaoxiao2021-03-06  38

This is the case, in order to use it for yourself, write a program that looks at the network TV. The program minimizes in the system tray so that when watching network TV, you can open it at any time, switch, more convenient, huh.

Previously, in the Visual C programming environment, write a system tray program, which should be more complicated, but also add a message processing function yourself. And in C #, this is very easy. Here is a simple step.

Add two main controls, Notifyicon controls, and ContextMenu controls for programs;

Set the Click event for the Menu menu and the corresponding menu for ContextMenu;

Add an ICON icon to the control Notifyicon's property icon and select the ContextMenu added to its contextMenu behavior as the context menu;

Set the form properties showintask = false, set the WindowsTate for the form for minimized;

Add event code in the initializationComponent () method of the main form

this.sizechanged = new system.eventhandler (this.form1_sizechanged)

Then add the following sizechanged event code

Private Void Form1_sizechanged (Object Sender, Eventargs E)

{

IF (this.WindowState == formwindowstate.minimized)

{

THIS.HIDE (); // Hide main form

THISIBLE = TRUE;

}

}

this.sizechanged = new system.eventhandler (this.form1_sizechanged)

Then add the following sizechanged event code

Private Void Form1_sizechanged (Object Sender, Eventargs E)

{

IF (this.WindowState == formwindowstate.minimized)

{

THIS.HIDE (); // Hide main form

THISIBLE = TRUE;

}

}

{

IF (this.WindowState == formwindowstate.minimized)

{

THIS.HIDE (); // Hide main form

THISIBLE = TRUE;

}

}

After the program starts, the automatic minimization is minimized to the system tray, and right-click on the tray icon, the menu of ContextMenu is displayed.

转载请注明原文地址:https://www.9cbs.com/read-65847.html

New Post(0)