C # simple knowledge of icon in the icon tray,
In the graduation project similar to QQ, there is a small icon that makes it difficult for me for a while, that is, a small tray icon.
The function to be completed is about to minimize the tray icon when the window is closed, and double-click the tray icon to display the tray icon.
Take the logon window as an Example
To have a tray icon, you first need a yyicon, which is found in the toolbox. Then, you have set the relevant attributes of policyic. First, you need an icon. I just flipped it online. I don't know which icon has been turned to. Sorry, let me use it for the time being. I guarantee that my level cannot be used for commercial purposes T ^ T, that is, setting the icon in this place is good.
If you need to right-click the tray icon and display some options and operations, you also need to add the contextmenustrip control (that is, the right-click shortcut control) in the window, this can also be found in the toolbox. Set the required functions ~
If the above steps are completed, it doesn't mean they are done. The two of them belong to two strangers who are independent from each other. If you want to right-click the icon, You need to hard-pull the relationship ~ You will be familiar with it when you move around ~
The important step here is to associate the shortcut created in notifyicon with the shortcut menu.
Then I want to minimize the window to the tray. This requires the formclosing event of the form.
If you set the visible attribute of policyicon to true (that is, visible), it will not be closed under normal circumstances. Therefore, you only need to 1. Disable it when you turn it off to minimize; 2. Minimize the window size.
1 # region close User Interface: Minimize to tray icon interface 2 private void Panel_FormClosing (object sender, FormClosingEventArgs e) 3 {4 // cancel close form 5 e. cancel = true; 6 // minimize the form by 7 this. windowState = FormWindowState. minimized; 8} 9 # endregion
The last point is to double-click the tray icon to display the user interface.
This is obviously the icon attribute. The above function is basically the window attribute, so his formclosing event is found in the window. Now it is the icon thing, check whether there are related function implementation events in the policyicon attribute, that is, mousedouble ~
1 # region double-click the tray icon to display the user interface 2 private void notifyIcon_MouseDoubleClick (object sender, MouseEventArgs e) 3 {4 if (WindowState = FormWindowState. minimized) 5 {6 // restore the form to display 7 WindowState = FormWindowState. normal; 8 // activate the form and give it Focus 9 this. activate (); 10} 11} 12 # endregion