這樣:
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 );

解决方案 »

  1.   

    请问朋友,把OwnerDraw=true后,同时this.menuItem.shortcut和showshortcut也用不了了,应该如何设置它们的值?
    谢谢!
      

  2.   

    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)));}