Using System;
Using System. Drawing;
Using System. Collections;
Using System. ComponentModel;
Using System. Windows. Forms;
Using System. Data;
Namespace Policy
{
/// <Summary>
/// Summary of Form1.
/// </Summary>
Public class Form1: System. Windows. Forms. Form
{
P rivate System. Windows. Forms. MainMenu mainMenu1;
P rivate System. Windows. Forms. MenuItem menuItem1;
P rivate System. Windows. Forms. MenuItem menuItem4;
P rivate System. Windows. Forms. MenuItem menuItem2;
P rivate System. Windows. Forms. policyicon policyicon1;
P rivate System. Windows. Forms. MenuItem menuItem3;
P rivate system. Windows. Forms. contextmenu contextmenu1;
P rivate system. Windows. Forms. picturebox picturebox1;
P rivate system. Windows. Forms. menuitem menuitem5;
P rivate system. Windows. Forms. menuitem menuitem6;
P rivate system. Windows. Forms. menuitem menuitem7;
P rivate system. Windows. Forms. menuitem menuitem8;
P rivate system. componentmodel. icontainer components;
Public form1 ()
{
//
// Required for Windows Form Designer support
//
Initializecomponent ();
//
// Todo: add Any constructor code after initializecomponent calls
//
}
/// <Summary>
/// Clear all resources in use.
/// </Summary>
Protected override void Dispose (bool disposing)
{
If (disposing)
{
If (components! = Null)
{
Components. Dispose ();
}
}
Base. Dispose (disposing );
}
# Region code generated by Windows Form Designer
/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
P rivate void InitializeComponent ()
{
This. components = new System. ComponentModel. Container ();
System. Resources. ResourceManager resources = new System. Resources. ResourceManager (typeof (Form1 ));
This. mainMenu1 = new System. Windows. Forms. MainMenu ();
This. menuItem1 = new System. Windows. Forms. MenuItem ();
This. menuItem2 = new System. Windows. Forms. MenuItem ();
This. menuItem5 = new System. Windows. Forms. MenuItem ();
This. menuItem3 = new System. Windows. Forms. MenuItem ();
This. menuItem6 = new System. Windows. Forms. MenuItem ();
This. menuItem7 = new System. Windows. Forms. MenuItem ();
This. menuItem8 = new System. Windows. Forms. MenuItem ();
This. menuItem4 = new System. Windows. Forms. MenuItem ();
This. policyicon1 = new System. Windows. Forms. policyicon (this. components );
This. contextMenu1 = new System. Windows. Forms. ContextMenu ();
This. pictureBox1 = new System. Windows. Forms. PictureBox ();
This. SuspendLayout ();
//
// MainMenu1
//
This. mainMenu1.MenuItems. AddRange (new System. Windows. Forms. MenuItem [] {
This. menuItem1 });
//
// Menuitem1
//
This. menuitem1.index = 0;
This. menuitem1.menuitems. addrange (new system. Windows. Forms. menuitem [] {
This. menuitem2,
This. menuitem5,
This. menuitem3,
This. menuitem6,
This. menuItem7,
This. menuItem8,
This. menuItem4 });
This. menuItem1.Text = "View (& V )";
//
// MenuItem2
//
This. menuItem2.Index = 0;
This. menuItem2.Text = "place on system tray (& N )";
This. menuItem2.Click + = new System. EventHandler (this. menuItem2_Click );
//
// Menuitem5
//
This. menuitem5.index = 1;
This. menuitem5.text = "-";
//
// Menuitem3
//
This. menuitem3.index = 2;
This. menuitem3.text = "restore normal display (& R )";
This. menuitem3.click + = new system. eventhandler (this. menuitem3_click );
//
// Menuitem6
//
This. menuitem6.index = 3;
This. menuitem6.text = "-";
//
// Menuitem7
//
This. menuitem7.index = 4;
This. menuitem7.text = "both the tray and the form (& T )";
This. menuitem7.click + = new system. eventhandler (this. menuitem7_click );
//
// Menuitem8
//
This. menuitem8.index = 5;
This. menuitem8.text = "-";
//
// Menuitem4
//
This. menuitem4.index = 6;
This. menuitem4.text = "close (& C )";
This. menuitem4.click + = new system. eventhandler (this. menuitem4_click );
//
// Policyicon1
//
This. policyicon1.contextmenu = This. contextmenu1;
This. policyicon1.icon = (system. Drawing. Icon) (resources. GetObject ("policyicon1.icon ")));
This. policyicon1.text = "this is a demo tray instance program ";
//
// Picturebox1
//
This. picturebox1.dock = system. Windows. Forms. dockstyle. Fill;
This. picturebox1.image = (system. Drawing. Image) (resources. GetObject ("picturebox1.image ")));
This. picturebox1.location = new system. Drawing. Point (0, 0 );
This. picturebox1.name = "picturebox1 ";
This. picturebox1.size = new system. Drawing. Size (336,169 );
This. pictureBox1.SizeMode = System. Windows. Forms. PictureBoxSizeMode. StretchImage;
This. pictureBox1.TabIndex = 0;
This. pictureBox1.TabStop = false;
//
// Form1
//
This. AutoScaleBaseSize = new System. Drawing. Size (6, 14 );
This. ClientSize = new System. Drawing. Size (336,169 );
This. Controls. Add (this. pictureBox1 );
This. Menu = this. mainMenu1;
This. Name = "Form1 ";
This. StartPosition = System. Windows. Forms. FormStartPosition. CenterScreen;
This. Text = "demonstrate how to use the tray control ";
This. Load + = new System. EventHandler (this. form#load );
This. ResumeLayout (false );
}
# Endregion
/// <Summary>
/// Main entry point of the application.
/// </Summary>
[STAThread]
Static void Main ()
{
Application. Run (new Form1 ());
}
P rivate void menuItem4_Click (object sender, System. EventArgs e)
{// Close the application
This. policyicon1.visible = false;
This. Close ();
Application. Exit ();
}
P rivate void menuItem2_Click (object sender, System. EventArgs e)
{// Display the tray icon
This. Visible = false;
This. policyicon1.visible = true;
}
P rivate void menuItem3_Click (object sender, System. EventArgs e)
{// Display the main form
This. Visible = true;
This. policyicon1.visible = false;
}
P rivate void Form1_Load (object sender, System. EventArgs e)
{// Copy the menu item of the main menu to the context menu
// Copy to the "place to system tray (N)" menu item
This. contextMenu1.MenuItems. Add (this. menuItem2.CloneMenu ());
// Copy the menu item of the separator line
This. contextMenu1.MenuItems. Add (this. menuItem5.CloneMenu ());
// Copy to the "restore normal display (R)" menu item
This. contextMenu1.MenuItems. Add (this. menuItem3.CloneMenu ());
// Copy the menu item of the separator line
This. contextMenu1.MenuItems. Add (this. menuItem6.CloneMenu ());
// Copy to the "close (C)" menu item
This. contextMenu1.MenuItems. Add (this. menuItem4.CloneMenu ());
// Copy the menu item of the separator line
This. contextMenu1.MenuItems. Add (this. menuItem8.CloneMenu ());
// Copy to the "Display (T) at the same time on the tray and form" menu item
This. contextMenu1.MenuItems. Add (this. menuItem7.CloneMenu ());
// This. contextMenu1.MergeMenu (this. mainMenu1 .);
}
P rivate void menuItem7_Click (object sender, System. EventArgs e)
{// Both the tray and form are displayed.
This. Visible = true;
This. policyicon1.visible = true;
}
}
}