本文整理汇总了C#中System.Windows.Forms.MainMenu类的典型用法代码示例。如果您正苦于以下问题:C# MainMenu类的具体用法?C# MainMenu怎么用?C# MainMenu使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MainMenu类属于System.Windows.Forms命名空间,在下文中一共展示了MainMenu类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMyMainMenu
public void CreateMyMainMenu()
{
// Create an empty MainMenu.
MainMenu mainMenu1 = new MainMenu();
MenuItem menuItem1 = new MenuItem();
MenuItem menuItem2 = new MenuItem();
menuItem1.Text = "File";
menuItem2.Text = "Edit";
// Add two MenuItem objects to the MainMenu.
mainMenu1.MenuItems.Add(menuItem1);
mainMenu1.MenuItems.Add(menuItem2);
// Bind the MainMenu to Form1.
Menu = mainMenu1;
}
示例2: new MainMenu()
/*
C#: The Complete Reference
by Herbert Schildt
Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// Add a Main Menu.
using System;
using System.Windows.Forms;
public class MenuForm : Form {
MainMenu MyMenu;
public MenuForm() {
Text = "Adding a Main Menu";
// Create a main menu object.
MyMenu = new MainMenu();
// Add top-level menu items to the menu.
MenuItem m1 = new MenuItem("File");
MyMenu.MenuItems.Add(m1);
MenuItem m2 = new MenuItem("Tools");
MyMenu.MenuItems.Add(m2);
// Create File submenu
MenuItem subm1 = new MenuItem("Open");
m1.MenuItems.Add(subm1);
MenuItem subm2 = new MenuItem("Close");
m1.MenuItems.Add(subm2);
MenuItem subm3 = new MenuItem("Exit");
m1.MenuItems.Add(subm3);
// Create Tools submenu
MenuItem subm4 = new MenuItem("Coordinates");
m2.MenuItems.Add(subm4);
MenuItem subm5 = new MenuItem("Change Size");
m2.MenuItems.Add(subm5);
MenuItem subm6 = new MenuItem("Restore");
m2.MenuItems.Add(subm6);
// Add event handlers for the menu items.
subm1.Click += new EventHandler(MMOpenClick);
subm2.Click += new EventHandler(MMCloseClick);
subm3.Click += new EventHandler(MMExitClick);
subm4.Click += new EventHandler(MMCoordClick);
subm5.Click += new EventHandler(MMChangeClick);
subm6.Click += new EventHandler(MMRestoreClick);
// Assign the menu to the form.
Menu = MyMenu;
}
[STAThread]
public static void Main() {
MenuForm skel = new MenuForm();
Application.Run(skel);
}
// Handler for main menu Coordinates selection.
protected void MMCoordClick(object who, EventArgs e) {
// Create a string that contains the cooridinates.
string size =
String.Format("{0}: {1}, {2}\n{3}: {4}, {5} ",
"Top, Left", Top, Left,
"Bottom, Right", Bottom, Right);
// Display a message box.
MessageBox.Show(size, "Window Coordinates",
MessageBoxButtons.OK);
}
// Handler for main menu Change selection.
protected void MMChangeClick(object who, EventArgs e) {
Width = Height = 200;
}
// Handler for main menu Restore selection.
protected void MMRestoreClick(object who, EventArgs e) {
Width = Height = 300;
}
// Handler for main menu Open selection.
protected void MMOpenClick(object who, EventArgs e) {
MessageBox.Show("Inactive", "Inactive",
MessageBoxButtons.OK);
}
// Handler for main menu Open selection.
protected void MMCloseClick(object who, EventArgs e) {
MessageBox.Show("Inactive", "Inactive",
MessageBoxButtons.OK);
}
// Handler for main menu Exit selection.
protected void MMExitClick(object who, EventArgs e) {
DialogResult result = MessageBox.Show("Stop Program?",
"Terminate",
MessageBoxButtons.YesNo);
if(result == DialogResult.Yes) Application.Exit();
}
}