• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# MenuItem类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Windows.Forms.MenuItem的典型用法代码示例。如果您正苦于以下问题:C# MenuItem类的具体用法?C# MenuItem怎么用?C# MenuItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MenuItem类属于System.Windows.Forms命名空间,在下文中一共展示了MenuItem类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: CreateMyMenu

public void CreateMyMenu()
    {
    // Set the caption for the top-level menu item.
    menuItem1.Text = "Edit";
    // Set the caption for the first submenu.
    menuItem2.Text = "Font Size";
    // Set the caption for menuItem2's first submenu.
    menuItem3.Text = "Small";
    // Set the checked property to true since this is the default value.
    menuItem3.Checked = true;
    // Define a shortcut key combination for the menu item.
    menuItem3.Shortcut = Shortcut.CtrlS;
    // Set the caption of the second sub menu item of menuItem2.
    menuItem4.Text = "Large";
    // Define a shortcut key combination for the menu item.
    menuItem4.Shortcut = Shortcut.CtrlL;
    // Set the index of the menu item so it is placed below the first submenu item.
    menuItem4.Index = 1;
    // Add menuItem3 and menuItem4 to menuItem2's list of menu items.
    menuItem2.MenuItems.Add(menuItem3);
    menuItem2.MenuItems.Add(menuItem4);
    // Add menuItem2 to menuItem1's list of menu items.
    menuItem1.MenuItems.Add(menuItem2);
    // Add menuItem1 to the MainMenu for displaying.
    mainMenu1.MenuItems.Add(menuItem1);
    }
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:26,代码来源:MenuItem


示例2: new MenuItem

//引入命名空间
using System;
using System.Drawing;
using System.Windows.Forms;
   
class OldFashionedMenu: Form
{
     MainMenu mmMain, mmFile, mmEdit;
   
     public static void Main()
     {
          Application.Run(new OldFashionedMenu());
     }
     public OldFashionedMenu()
     {
          EventHandler eh = new EventHandler(MenuOnClick);
   
          mmMain = new MainMenu(new MenuItem[] 
          { 
               new MenuItem("MAIN:"),
               new MenuItem("&File", new EventHandler(MenuFileOnClick)),
               new MenuItem("&Edit", new EventHandler(MenuEditOnClick))
          });
   
          mmFile = new MainMenu(new MenuItem[]
          {
               new MenuItem("FILE:"),
               new MenuItem("&New", eh),
               new MenuItem("&Open...", eh),
               new MenuItem("&Save", eh),
               new MenuItem("Save &As...", eh),
               new MenuItem("(&Main)", new EventHandler(MenuMainOnClick))
          });
          
          mmEdit = new MainMenu(new MenuItem[]
          {
               new MenuItem("EDIT:"),
               new MenuItem("Cu&t", eh),
               new MenuItem("&Copy", eh),
               new MenuItem("&Paste", eh),
               new MenuItem("De&lete", eh),
               new MenuItem("(&Main)", new EventHandler(MenuMainOnClick))
          });
   
          Menu = mmMain;
     }
     void MenuMainOnClick(object obj, EventArgs ea)
     {
          Menu = mmMain;
     }
     void MenuFileOnClick(object obj, EventArgs ea)
     {
          Menu = mmFile;
     }
     void MenuEditOnClick(object obj, EventArgs ea)
     {
          Menu = mmEdit;
     }
     void MenuOnClick(object obj, EventArgs ea)
     {
          MessageBox.Show("Menu item clicked!", Text);
     }
}
开发者ID:C#程序员,项目名称:System.Windows.Forms,代码行数:63,代码来源:MenuItem


示例3: new MenuItem("&Open...",new EventHandler(MenuFileOpenOnClick),Shortcut.CtrlO)

//引入命名空间
using System;
using System.Drawing;
using System.Windows.Forms;
   
class FirstMainMenu: Form
{
     public static void Main()
     {
          Application.Run(new FirstMainMenu());
     }
     public FirstMainMenu()
     {

          MenuItem miOpen = new MenuItem("&Open...",
                                   new EventHandler(MenuFileOpenOnClick),
                                   Shortcut.CtrlO);
   
          MenuItem miSave = new MenuItem("&Save",
                                   new EventHandler(MenuFileSaveOnClick),
                                   Shortcut.CtrlS);
   
          MenuItem miSaveAs = new MenuItem("Save &As...",
                                   new EventHandler(MenuFileSaveAsOnClick));
   
          MenuItem miDash = new MenuItem("-");
   
          MenuItem miExit = new MenuItem("E&xit",
                                   new EventHandler(MenuFileExitOnClick));
          MenuItem miFile = new MenuItem("&File",
                                   new MenuItem[] {miOpen, miSave, miSaveAs,
                                                   miDash, miExit });
          MenuItem miCut = new MenuItem("Cu&t",
                                   new EventHandler(MenuEditCutOnClick),
                                   Shortcut.CtrlX);
   
          MenuItem miCopy = new MenuItem("&Copy",
                                   new EventHandler(MenuEditCopyOnClick),
                                   Shortcut.CtrlC);
   
          MenuItem miPaste = new MenuItem("&Paste",
                                   new EventHandler(MenuEditPasteOnClick),
                                   Shortcut.CtrlV);
          MenuItem miEdit = new MenuItem("&Edit",
                                   new MenuItem[] {miCut, miCopy, miPaste});
   
          MenuItem miAbout = new MenuItem("&About FirstMainMenu...",
                                   new EventHandler(MenuHelpAboutOnClick));
          MenuItem miHelp = new MenuItem("&Help", 
                                   new MenuItem[] {miAbout});
   
          Menu = new MainMenu(new MenuItem[] {miFile, miEdit, miHelp});
     }
     void MenuFileOpenOnClick(object obj, EventArgs ea)
     {
          MessageBox.Show("File Open item clicked!", Text);
     }
     void MenuFileSaveOnClick(object obj, EventArgs ea)
     {
          MessageBox.Show("File Save item clicked!", Text);
     }
     void MenuFileSaveAsOnClick(object obj, EventArgs ea)
     {
          MessageBox.Show("File Save As item clicked!", Text);
     }
     void MenuFileExitOnClick(object obj, EventArgs ea)
     {
          Close();
     }
     void MenuEditCutOnClick(object obj, EventArgs ea)
     {
          MessageBox.Show("Edit Cut item clicked!", Text);
     }
     void MenuEditCopyOnClick(object obj, EventArgs ea)
     {
          MessageBox.Show("Edit Copy item clicked!", Text);
     }
     void MenuEditPasteOnClick(object obj, EventArgs ea)
     {
          MessageBox.Show("Edit Paste item clicked!", Text);
     }
     void MenuHelpAboutOnClick(object obj, EventArgs ea)
     {
          MessageBox.Show(Text + " ?");
     }
}
开发者ID:C#程序员,项目名称:System.Windows.Forms,代码行数:86,代码来源:MenuItem



注:本文中的System.Windows.Forms.MenuItem类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# MenuStrip类代码示例发布时间:2022-05-26
下一篇:
C# Menu类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap