要实现这个功能.必须将菜单的OwnerDraw属性设置为true,然后自已绘制.

解决方案 »

  1.   

    设置菜单属性为重绘 OwnerDraw属性设置为true ,不需要系统处理
    /// <summary>
    /// 重绘菜单
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void DrawMenu(object sender,System.Windows.Forms.DrawItemEventArgs e)
    {
    SubApplicationMenuItem m=(SubApplicationMenuItem)sender;
    Brush brush = null;
    System.Drawing.Graphics g= e.Graphics;

    try
    {
    g.FillRectangle(new SolidBrush(Color.White),e.Bounds.Left+20,e.Bounds.Top,e.Bounds.Width,e.Bounds.Height);
    bool selected = (e.State & DrawItemState.Selected) > 0;
    if (selected || ((e.State & DrawItemState.HotLight) > 0)) 
    {
    g.DrawRectangle(new Pen(Color.FromArgb(10,36,106)), e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 1);
    g.FillRectangle(new SolidBrush(Color.FromArgb(182,189,210)),e.Bounds.X+1, e.Bounds.Y+1, e.Bounds.Width - 2, e.Bounds.Height - 2);
    }
    else
    {
    g.FillRectangle(new SolidBrush(Color.FromArgb(219,216,209)),e.Bounds.X, e.Bounds.Y, 20, e.Bounds.Height);
    g.FillRectangle(new SolidBrush(Color.FromArgb(249,248,247)),e.Bounds.X+20, e.Bounds.Y, e.Bounds.Width-20, e.Bounds.Height);
    } if (m.Enabled)
    if (selected || ((e.State & DrawItemState.HotLight) > 0))
    {
    brush = new SolidBrush(Color.Black);
    }
    else
    {
    brush = new SolidBrush(Color.Black);
    }
    else
    {
    brush = new SolidBrush(Color.FromArgb(120, SystemColors.MenuText));
    }

    //文本
    string s=m.Text;
    string mText=null;
    int i=s.IndexOf("&",0);
    if(i>0)
    {
    mText=s.Substring(0,i)+(s.Substring(i+1,1)+s.Substring(i+2,s.Length-i-2));
    }
    else
    {
    mText=s;
    }
    g.DrawString(mText,SystemInformation.MenuFont,brush,e.Bounds.Left+25,e.Bounds.Top+3); //图标
    int top=0;
    foreach(MenuItem mItem in m.Parent.MenuItems)
    {
    if(mItem!=m)
    {
    if(mItem.Text=="-")
    {
    top+=8;
    }
    else
    {
    top+=20;
    }
    }
    else
    {
    break;
    }
    }
    try
    {
    if (selected || ((e.State & DrawItemState.HotLight) > 0)) 
    {
    g.DrawIcon(m.Icon,new Rectangle(2+1,top+2+1,16,16));
    g.DrawIcon(m.Icon,new Rectangle(2,top+2,16,16));
    }
    else
    {
    g.DrawIcon(m.Icon,new Rectangle(2+1,top+2+1,16,16));
    }
    }
    catch(Exception){}
    }
    catch(Exception){}
    g.Dispose();
    }
      

  2.   

    同意  haiwangstar(南河三(来自于小犬星座)) 
    这一点delphi实现的话要方便