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


C# MenuItem.Checked属性代码示例

本文整理汇总了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;
    }
 }
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:35,代码来源:MenuItem.Checked

示例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");
          }
     }
}
开发者ID:C#程序员,项目名称:System.Windows.Forms,代码行数:68,代码来源:MenuItem.Checked


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