本文整理汇总了C#中System.Windows.Forms.MenuItem.Checked属性的典型用法代码示例。如果您正苦于以下问题:C# MenuItem.Checked属性的具体用法?C# MenuItem.Checked怎么用?C# MenuItem.Checked使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Windows.Forms.MenuItem
的用法示例。
在下文中一共展示了MenuItem.Checked属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MyMenuClick
// The following event handler would be connected to three menu items.
private void MyMenuClick(Object sender, EventArgs e)
{
// Determine if clicked menu item is the Blue menu item.
if(sender == menuItemBlue)
{
// Set the checkmark for the menuItemBlue menu item.
menuItemBlue.Checked = true;
// Uncheck the menuItemRed and menuItemGreen menu items.
menuItemRed.Checked = false;
menuItemGreen.Checked = false;
// Set the color of the text in the TextBox control to Blue.
textBox1.ForeColor = Color.Blue;
}
else if(sender == menuItemRed)
{
// Set the checkmark for the menuItemRed menu item.
menuItemRed.Checked = true;
// Uncheck the menuItemBlue and menuItemGreen menu items.
menuItemBlue.Checked = false;
menuItemGreen.Checked = false;
// Set the color of the text in the TextBox control to Red.
textBox1.ForeColor = Color.Red;
}
else
{
// Set the checkmark for the menuItemGreen.
menuItemGreen.Checked = true;
// Uncheck the menuItemRed and menuItemBlue menu items.
menuItemBlue.Checked = false;
menuItemRed.Checked = false;
// Set the color of the text in the TextBox control to Blue.
textBox1.ForeColor = Color.Green;
}
}
示例2: Main
//引入命名空间
using System;
using System.Drawing;
using System.Windows.Forms;
class CheckAndRadioCheck: Form
{
MenuItem miColor, miFill;
public static void Main()
{
Application.Run(new CheckAndRadioCheck());
}
public CheckAndRadioCheck()
{
ResizeRedraw = true;
string[] astrColor = {"Black", "Blue", "Green", "Cyan",
"Red", "Magenta", "Yellow", "White"};
MenuItem[] ami = new MenuItem[astrColor.Length + 2];
EventHandler ehColor = new EventHandler(MenuFormatColorOnClick);
for (int i = 0; i < astrColor.Length; i++)
{
ami[i] = new MenuItem(astrColor[i], ehColor);
ami[i].RadioCheck = true;
}
miColor = ami[0];
miColor.Checked = true;
ami[astrColor.Length] = new MenuItem("-");
miFill = new MenuItem("&Fill",new EventHandler(MenuFormatFillOnClick));
ami[astrColor.Length + 1] = miFill;
MenuItem mi = new MenuItem("&Format", ami);
Menu = new MainMenu(new MenuItem[] {mi});
}
void MenuFormatColorOnClick(object obj, EventArgs ea)
{
miColor.Checked = false;
miColor = (MenuItem)obj;
miColor.Checked = true;
Invalidate();
}
void MenuFormatFillOnClick(object obj, EventArgs ea)
{
MenuItem mi = (MenuItem)obj;
mi.Checked ^= true;
Invalidate();
}
protected override void OnPaint(PaintEventArgs pea)
{
if (miFill.Checked)
{
Console.WriteLine("fill");
}
else
{
Console.WriteLine("not fill");
}
}
}