Hatch Brush Menu : 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 
Hatch Brush Menu
 
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
   
class HatchBrushMenu: Form
{
     HatchStyleMenuItem hsmiChecked;
     const int iMin = 0, iMax = 52;
     public static void Main()
     {
          Application.Run(new HatchBrushMenu());
     }
     public HatchBrushMenu()
     {
          ResizeRedraw = true;
   
          Menu = new MainMenu();
          Menu.MenuItems.Add("&Hatch-Style");
   
          for (HatchStyle hs = (HatchStyle)iMin; hs <= (HatchStyle)iMax;hs++)
          {
               HatchStyleMenuItem hsmi = new HatchStyleMenuItem();
   
               hsmi.HatchStyle = hs;
               hsmi.Click += new EventHandler(MenuHatchStyleOnClick);
   
               if ((int)hs % == 0)
                    hsmi.BarBreak = true;
   
               Menu.MenuItems[0].MenuItems.Add(hsmi);
          }
          hsmiChecked = (HatchStyleMenuItemMenu.MenuItems[0].MenuItems[0];
          hsmiChecked.Checked = true;
     }
     void MenuHatchStyleOnClick(object obj, EventArgs ea)
     {
          hsmiChecked.Checked = false;
          hsmiChecked = (HatchStyleMenuItemobj;
          hsmiChecked.Checked = true;
   
          Invalidate();
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          Graphics grfx = pea.Graphics;
   
          HatchBrush hbrush = new HatchBrush(hsmiChecked.HatchStyle,
                                             Color.White, Color.Black);
   
          grfx.FillEllipse(hbrush, ClientRectangle);
     }
}
class HatchStyleMenuItem: MenuItem
{
     const    int cxImage = 32, cyImage = 32, iMargin = 2;
     readonly int cxCheck, cyCheck; 
   
     public HatchStyle HatchStyle;
   
     public HatchStyleMenuItem()
     {
          OwnerDraw = true;
   
          cxCheck = SystemInformation.MenuCheckSize.Width;
          cyCheck = SystemInformation.MenuCheckSize.Height;
     }
     protected override void OnMeasureItem(MeasureItemEventArgs miea)
     {
          miea.ItemWidth  = * cxImage + * iMargin - cxCheck;
          miea.ItemHeight =     cyImage + * iMargin;
     }
     protected override void OnDrawItem(DrawItemEventArgs diea)
     {
          diea.DrawBackground();
   
          if ((diea.State & DrawItemState.Checked!= 0)
          {
                ControlPaint.DrawMenuGlyph(diea.Graphics,
                                   diea.Bounds.Location.X + iMargin, 
                                   diea.Bounds.Location.Y + iMargin,
                                   cxImage, cyImage, MenuGlyph.Checkmark);
          }
          HatchBrush hbrush = new HatchBrush(HatchStyle,
                                             Color.White, Color.Black);
   
          diea.Graphics.FillRectangle(hbrush, 
                              diea.Bounds.X + * iMargin + cxImage,
                              diea.Bounds.Y + iMargin, cxImage, cyImage);
     }
}

 
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.RadioCheck MenuItem
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.