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.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# Book
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
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.