All those who have used jingting know that the software can be minimized to the system tray in the lower right corner. Recently I made a small tool and want to implement similar functions. When you click a button or shortcut key, Program Minimize to the system tray and use the shortcut key again to restore.
The first is to solve the problem of how to minimize to the system tray and restore it:
The method is to use the policyicon control, which is the button shown after the minimization, mainly to configure a beautiful icon :). Add the following to the program: Code :
1 Void Minimizedtonormal ()
2 {
3 This . Visible = True ;
4 This . Windowstate = Formwindowstate. normal;
5 Policyicon1.visible = False ;
6
7 }
8 Void Normaltominimized ()
9 {
10 This . Windowstate = Formwindowstate. minimized;
11 This . Visible = False ;
12 This . Policyicon1.visible = True ;
13 }
Normaltominimized () hides the current form and displays the tray notification button (this button is initially hidden ).
Minimizedtonormal () is to re-display the form and hide the tray notification button.
The following describes how to minimize system tray and recovery through shortcut key control by calling Windows API
Registerhotkey ()
Unregisterhotkey () APIs.
When you click this shortcut key, you can call normaltominimized () and minimizedtonormal () to minimize and restore the system.
You can also directly use the two files in the following compressed package, which are included in the project. This is a system shortcut key control written by foreigners. Very convenient :)
/Files/dxfcv222/systemhotkey.rar
The Code is as follows:
1 Void Systemhotkeyreceivpressed ( Object Sender, eventargs E)
2 {
3 If ( This . Policyicon1.visible)
4 {
5Minimizedtonormal ();
6}
7 Else
8 {
9Normaltominimized ();
10}
11 }