本文整理汇总了C#中System.Windows.Forms.MenuItem.DrawItem事件的典型用法代码示例。如果您正苦于以下问题:C# MenuItem.DrawItem事件的具体用法?C# MenuItem.DrawItem怎么用?C# MenuItem.DrawItem使用的例子?那么, 这里精选的事件代码示例或许可以为您提供帮助。您也可以进一步了解该事件所在类System.Windows.Forms.MenuItem
的用法示例。
在下文中一共展示了MenuItem.DrawItem事件的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: menuItem1_DrawItem
// The DrawItem event handler.
private void menuItem1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
string myCaption = "Owner Draw Item1";
// Create a Brush and a Font with which to draw the item.
Brush myBrush = System.Drawing.Brushes.AliceBlue;
Font myFont = new Font(FontFamily.GenericSerif, 14, FontStyle.Underline, GraphicsUnit.Pixel);
SizeF mySizeF = e.Graphics.MeasureString(myCaption, myFont);
// Draw the item, and then draw a Rectangle around it.
e.Graphics.DrawString(myCaption, myFont, myBrush, e.Bounds.X, e.Bounds.Y);
e.Graphics.DrawRectangle(Pens.Black, new Rectangle(e.Bounds.X, e.Bounds.Y, Convert.ToInt32(mySizeF.Width), Convert.ToInt32(mySizeF.Height)));
}
示例2: Main
//引入命名空间
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);
}
}