当前位置: 首页>>代码示例>>C#>>正文


C# MenuItem.OnSelect方法代码示例

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


在下文中一共展示了MenuItem.OnSelect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MenuSelected

private void MenuSelected(object sender, System.EventArgs e)
{
   if (sender == menuOpen)
      statusBar1.Panels[0].Text = "Opens a file to edit";
   else if(sender == menuSave)
      statusBar1.Panels[0].Text = "Saves the current file";
   else if(sender == menuExit)
      statusBar1.Panels[0].Text = "Exits the application";
   else
      statusBar1.Panels[0].Text = "Ready";
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:11,代码来源:MenuItem.OnSelect

示例2: MenuItemHelp

//引入命名空间
using System;
using System.Drawing;
using System.Windows.Forms;
   
class MenuItemHelp: MenuItem
{
     StatusBarPanel sbpHelpPanel;
     string         strHelpText;

     public MenuItemHelp(string strText): base(strText)
     {
     }
     public StatusBarPanel HelpPanel
     {
          get { return sbpHelpPanel; }
          set { sbpHelpPanel = value; }
     }
     public string HelpText
     {
          get { return strHelpText; }
          set { strHelpText = value; }
     }
     protected override void OnSelect(EventArgs ea)
     {
          base.OnSelect(ea);
   
          if (HelpPanel != null)
               HelpPanel.Text = HelpText;
     }
}


class MenuHelpSubclass: Form
{
     StatusBarPanel sbpMenuHelp;
     string         strSavePanelText;
   
     public static void Main()
     {
          Application.Run(new MenuHelpSubclass());
     }
     public MenuHelpSubclass()
     {

          StatusBar sb = new StatusBar();
          sb.Parent = this;
          sb.ShowPanels = true;
   
          sbpMenuHelp = new StatusBarPanel();
          sbpMenuHelp.Text = "Ready";
          sbpMenuHelp.AutoSize = StatusBarPanelAutoSize.Spring;
   
          sb.Panels.Add(sbpMenuHelp);
   
          Menu = new MainMenu();
          
          MenuItemHelp mi = new MenuItemHelp("&File");
          mi.HelpPanel = sbpMenuHelp;
          mi.HelpText = "Commands for working with files";
          Menu.MenuItems.Add(mi);
   
          mi = new MenuItemHelp("&Open...");
          mi.HelpPanel = sbpMenuHelp;
          mi.HelpText = "Opens an existing document";
          Menu.MenuItems[0].MenuItems.Add(mi);
          
          mi = new MenuItemHelp("&Close");
          mi.HelpPanel = sbpMenuHelp;
          mi.HelpText = "Closes the current document";
          Menu.MenuItems[0].MenuItems.Add(mi);
   
          mi = new MenuItemHelp("&Save");
          mi.HelpPanel = sbpMenuHelp;
          mi.HelpText = "Saves the current document";
          Menu.MenuItems[0].MenuItems.Add(mi);
   
          mi = new MenuItemHelp("&Edit");
          mi.HelpPanel = sbpMenuHelp;
          mi.HelpText = "Commands for editing the document";
          Menu.MenuItems.Add(mi);
   
          mi = new MenuItemHelp("Cu&t");
          mi.HelpPanel = sbpMenuHelp;
          mi.HelpText = "Deletes the selection and " +
                        "copies it to the clipboard";
          Menu.MenuItems[1].MenuItems.Add(mi);
          
          mi = new MenuItemHelp("&Copy");
          mi.HelpPanel = sbpMenuHelp;
          mi.HelpText = "Copies the selection to the clipboard";
          Menu.MenuItems[1].MenuItems.Add(mi);
   
          mi = new MenuItemHelp("&Paste");
          mi.HelpPanel = sbpMenuHelp;
          mi.HelpText = "Replaces the current selection " +
                        "with the clipboard contents";
          Menu.MenuItems[1].MenuItems.Add(mi);
     }
     protected override void OnMenuStart(EventArgs ea)
     {
          strSavePanelText = sbpMenuHelp.Text;
     }
     protected override void OnMenuComplete(EventArgs ea)
     {
          sbpMenuHelp.Text = strSavePanelText;
     }
}
开发者ID:C#程序员,项目名称:System.Windows.Forms,代码行数:108,代码来源:MenuItem.OnSelect


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