RadioCheck 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 
RadioCheck MenuItem
 
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[inew MenuItem(astrColor[i], ehColor);
               ami[i].RadioCheck = true;
          }
          miColor = ami[0];
          miColor.Checked = true;
   
          ami[astrColor.Lengthnew 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.Creating a menu on the fly.
3.Set MenuItem ShortCut
4.Font Menu
5.Subclass 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.