MenuItem.Checked : MenuItem « System.Windows.Forms « C# / C Sharp by API






MenuItem.Checked

 

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");
          }
     }
}

   
  








Related examples in the same category

1.new MenuItem
2.new MenuItem("&Open...",new EventHandler(MenuFileOpenOnClick),Shortcut.CtrlO)
3.extends MenuItem
4.MenuItem.Click
5.MenuItem.DrawItem
6.MenuItem.MeasureItem
7.MenuItem.MenuItems
8.MenuItem.OnSelect
9.MenuItem.Parent
10.MenuItem.Popup
11.MenuItem.Shortcut
12.MenuItem.Text