Subclass MenuItem : MenuItem « GUI Windows Form « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » GUI Windows Form » MenuItemScreenshots 
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 = (MenuItemColorobj;
          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; }
     }
}

 
Related examples in the same category
1.new MenuItem
2.Creating a menu on the fly.
3.Set MenuItem ShortCut
4.Font Menu
5.RadioCheck MenuItem
6.Hatch Brush Menu
7.Owner Drawn Menu ControlOwner Drawn Menu Control
8.Owner Drawn MenuOwner Drawn Menu
9.Add Help text for MenuItem
10.Help Menu
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.