MenuItem.DrawItem : MenuItem « System.Windows.Forms « C# / C Sharp by API






MenuItem.DrawItem

 
using System;
using System.Drawing;
using System.Windows.Forms;
   
class HelpMenu: Form
{
     Bitmap bmHelp;
   
     public static void Main()
     {
          Application.Run(new HelpMenu());
     }
     public HelpMenu()
     {
          bmHelp = new Bitmap(GetType(), "help.bmp");
   
          Menu = new MainMenu();
          Menu.MenuItems.Add("&Help");
   
          MenuItem mi     = new MenuItem("&Help");
          mi.OwnerDraw    = true;
          mi.Click       += new EventHandler(MenuHelpOnClick);
          mi.DrawItem    += new DrawItemEventHandler(MenuHelpOnDrawItem);
          mi.MeasureItem += new MeasureItemEventHandler(MenuHelpOnMeasureItem);
   
          Menu.MenuItems[0].MenuItems.Add(mi);
     }
     void MenuHelpOnMeasureItem(object obj, MeasureItemEventArgs miea)
     {
          miea.ItemWidth  = bmHelp.Width;
          miea.ItemHeight = bmHelp.Height;
     }
     void MenuHelpOnDrawItem(object obj, DrawItemEventArgs diea)
     {
          Rectangle rect = diea.Bounds;
          rect.X += diea.Bounds.Width - bmHelp.Width;
          rect.Width = bmHelp.Width;
   
          diea.DrawBackground();
          diea.Graphics.DrawImage(bmHelp, rect);
     }
     void MenuHelpOnClick(object obj, EventArgs ea)
     {
          MessageBox.Show("Help", Text);
     }
}

   
  








Related examples in the same category

1.new MenuItem
2.new MenuItem("&Open...",new EventHandler(MenuFileOpenOnClick),Shortcut.CtrlO)
3.extends MenuItem
4.MenuItem.Checked
5.MenuItem.Click
6.MenuItem.MeasureItem
7.MenuItem.MenuItems
8.MenuItem.OnSelect
9.MenuItem.Parent
10.MenuItem.Popup
11.MenuItem.Shortcut
12.MenuItem.Text