C # minimal program to System Tray

Source: Internet
Author: User
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 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.