Subclass MenuItem : MenuItem : GUI Windows Form C# Source Code


Custom Search

C# Source Code » GUI Windows Form » MenuItem »

 

Subclass MenuItem








    
 

using System;
using System.Drawing;
using System.Windows.Forms;
   
class BetterContextMenu: Form
{
     MenuItemColor micColor;
   
     public static void Main()
     {
          Application.Run(new BetterContextMenu());
     }
     public BetterContextMenu()
     {
          Text = "Better Context Menu Demo";
   
          EventHandler eh = new EventHandler(MenuColorOnClick);
   
          MenuItemColor[] amic = 
          {
               new MenuItemColor(Color.Black,   "&Black",   eh),
               new MenuItemColor(Color.Blue,    "B&lue",    eh),
               new MenuItemColor(Color.Green,   "&Green",   eh),
               new MenuItemColor(Color.Cyan,    "&Cyan",    eh),
               new MenuItemColor(Color.Red,     "&Red",     eh),
               new MenuItemColor(Color.Magenta, "&Magenta", eh),
               new MenuItemColor(Color.Yellow,  "&Yellow",  eh),
               new MenuItemColor(Color.White,   "&White",   eh)
          };
   
          foreach (MenuItemColor mic in amic)
               mic.RadioCheck = true;
   
          micColor = amic[3];
          micColor.Checked = true;
          BackColor = micColor.Color;
   
          ContextMenu = new ContextMenu(amic);
     }
     void MenuColorOnClick(object obj, EventArgs ea)
     {
          micColor.Checked = false;
          micColor = (MenuItemColor) obj;
          micColor.Checked = true;
   
          BackColor = micColor.Color;
     }
}
class MenuItemColor: MenuItem
{
     Color clr;
   
     public MenuItemColor(Color clr, string str, EventHandler eh):
                                                            base(str, eh)
     {
          Color = clr;
     }
     public Color Color
     {
          get { return clr; }
          set { clr = value; }
     }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo GUI Windows Form
» MenuItem