本文整理汇总了C#中System.Windows.Forms.Form.Menu属性的典型用法代码示例。如果您正苦于以下问题:C# Form.Menu属性的具体用法?C# Form.Menu怎么用?C# Form.Menu使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Windows.Forms.Form
的用法示例。
在下文中一共展示了Form.Menu属性的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: AddMenuForm
//引入命名空间
using System;
using System.Windows.Forms;
class AddMenuForm : Form {
MainMenu MyMenu;
public AddMenuForm() {
Text = "Adding a Main Menu";
MyMenu = new MainMenu();
MenuItem m1 = new MenuItem("File");
MyMenu.MenuItems.Add(m1);
MenuItem m2 = new MenuItem("Tools");
MyMenu.MenuItems.Add(m2);
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);
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);
subm1.Click += MMOpenClick;
subm2.Click += MMCloseClick;
subm3.Click += MMExitClick;
subm4.Click += MMCoordClick;
subm5.Click += MMChangeClick;
subm6.Click += MMRestoreClick;
Menu = MyMenu;
}
[STAThread]
public static void Main() {
AddMenuForm skel = new AddMenuForm();
Application.Run(skel);
}
protected void MMCoordClick(object who, EventArgs e) {
}
protected void MMChangeClick(object who, EventArgs e) {
}
protected void MMRestoreClick(object who, EventArgs e) {
}
protected void MMOpenClick(object who, EventArgs e) {
Console.WriteLine("MMOpenClick");
}
protected void MMCloseClick(object who, EventArgs e) {
Console.WriteLine("MMCloseClick");
}
protected void MMExitClick(object who, EventArgs e) {
Console.WriteLine("Exit");
}
}