這樣:
Rectangle rc = new Rectangle ( e.Bounds.X + 1 , e.Bounds.Y + 1 , e.Bounds.Width - 5 , e.Bounds.Height - 1 );
MenuItem mnuItem = (MenuItem) sender;
string sMenu = mnuItem.Text;
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
e.Graphics.DrawString ( sMenu , new Font ( "Ariel" , 9 ) , new SolidBrush ( Color.Black ) , rc ,sf );
Rectangle rc = new Rectangle ( e.Bounds.X + 1 , e.Bounds.Y + 1 , e.Bounds.Width - 5 , e.Bounds.Height - 1 );
MenuItem mnuItem = (MenuItem) sender;
string sMenu = mnuItem.Text;
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
e.Graphics.DrawString ( sMenu , new Font ( "Ariel" , 9 ) , new SolidBrush ( Color.Black ) , rc ,sf );
谢谢!
{ 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)));}