本文整理汇总了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";
}
示例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;
}
}