C# webForm开发(自绘菜单)

一.建立好菜单

把每个菜单的 OwnerDraw属性设置为true

 

二.给菜单添加事件

  private void menuItem2_MeasureItem(object sender, System.Windows.Forms.MeasureItemEventArgs e)
  {
   e.ItemWidth=130;//每个菜单的宽高
   e.ItemHeight=25;
  }

  private void menuItem2_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
  {
   if((e.State & DrawItemState.Selected) == DrawItemState.Selected)
   {
    e.Graphics.FillRectangle(Brushes.Blue, e.Bounds);
   }
   else
//    BitBlt(e.Graphics.GetHdc(),e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height,bmp,
//     e.Bounds.X, e.Bounds.Y,SrcCopy);
    e.Graphics.DrawImage(bmp,e.Bounds,e.Bounds.X,e.Bounds.Y,e.Bounds.Width,e.Bounds.Height,
     GraphicsUnit.Pixel );
   str=((MenuItem)sender).Text;
   e.Graphics.DrawString(str,e.Font,Brushes.White,e.Bounds.X+8,e.Bounds.Y+4);

  }

 

posted @ 2012-05-03 14:39  翱翔软件  阅读(2376)  评论(1)    收藏  举报

欢迎访问翱翔软件