A dedicated development TrayProgramThe policyicon component. The following describes the specific usage of this component and the main skills in programming.
(1) how to hide the form after running the program:
We know that the main form cannot be seen after the pallet program runs. It will only be displayed on the toolbar. When you use Visual C # to design such a program, you can use either of the following methods to prevent the main form from being displayed after the program runs. One of the methods is to reload the onactivated () event in the main form. The onactivated () event is triggered only when the form is activated. By reloading this event, you can hide the main form. ProcedureCodeAs follows:
Protected override void onactivated (eventargs E)
{
This. Hide ();
}
Another method is to initialize the main form, and do not display it by setting the attributes of the main form. The specific program code is as follows:
The second method is used in the program described in this article.
(2) how to set the display icon for the tray program:
One attribute icon in the categoryicon component is used to set the tray icon. Because Visual C # Is A Complete OOP (Object-Oriented) language, anything in Visual C # can be processed as an object. Of course, corresponding to an icon, you can also use the object method to process it. The following statement is used to obtain an icon object:
Private icon mnettrayicon = new icon ("tray. ICO ");
Note: In compiled programs, a tray. ICO icon file must exist in the same directory; otherwise, errors may occur during program running.
Use the following statement to pay the icon object to the icon attribute in the notifyicon component. If the program is correctly compiled, the icon is displayed in the toolbar.
Trayicon. Icon = mnettrayicon;
(3). Set the text content displayed when the mouse stays on the program Tray:
The yyicon component has an attribute text. Set the content of this attribute, that is, the content displayed by hovering the cursor over the tray icon. The statement is as follows:
Trayicon. Text = "using Visual C # As a pallet program" + "N" + "Author: Ma Jinhu on 2001.12.08 ";
(4) how to add a menu in the pallet program:
The categoryicon component has an object called contextmenu. The menu displayed in the pallet program is implemented by setting this object. The following program code adds a menu item to the pallet program:
Policyiconmnu = new contextmenu (mnuitms );
Trayicon. contextmenu = policyiconmnu;
// Set the menu for the pallet Program
(5) how to set the content of the contextmenu object:
The contextmenu object is the structure of the menu of the pallet program. Therefore, it is critical to set this object. In a program, you define a menu item array and set different values for this array (which includes some menu attributes and events ), then assign this array to the contextmenu object at the same time to set the contextmenu object. The specific code in the program is as follows:
// Define a menuitem array and assign the array to the contextmenu object at the same time
Menuitem [] mnuitms = new menuitem [3];
Mnuitms [0] = new menuitem ();
Mnuitms [0]. Text = "Use Visual C # As the pallet program! ";
// Add the set contextmenu object to the tray Program
After the contextmenu object is successfully added, when the program compilation is complete, When you right-click the tray icon, the program automatically displays the contextmenu object encapsulated menu.
Ii. procedures described in this articleSource code(Tray. CS ):
This. Text = "Use Visual C # As the pallet program! ";
This. resumelayout (false );
}
Static void main ()
{
Application. Run (new tray ());
}
}
Iii. Summary:
from the above introduction, we can see that using Visual C # To create a pallet program is not a complicated task, but a relatively easy task. We can also understand that although Visual C # is a powerful programming language, it is just an open.. NET Framework SDK is the key of this rich-content software package. NET programming language has a broader stage to display its own functions.
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