此主题相关图片如下: MyMenuItem : .Windows.Forms.MenuItem
以下是引用片段:
{
publicMyMenuItem
{
//这里很重要必须把OwerDraw设为true这样可以自己画菜单否则便是让操作系统画菜单了默认是false
this.OwnerDraw=true;
}
protectedoverridevoidOnDrawItem(SysDrawItemEventArgse)
{
//要重画菜单是没有OnPa思路方法重载只有重载OnDrawItem思路方法!
Graphicsg=e.Graphics;
g.SmoothingMode=SmoothingMode.AntiAlias;//抗锯齿
Fontf=Font(FontFamily.GenericSer,12,FontStyle.Regular,GraphicsUnit.Pixel);//设定菜单字体
Penp=Pen(Color.Navy,1);//这是画边框字体
(e.StateDrawItemState.NoAccelerator)//开始右键单击出现菜单但是鼠标并没有移上去
{//用白色底色
g.FillRectangle(Brushes.WhiteSmoke,e.Bounds.X-2,e.Bounds.Y-2,121,23);
}
//鼠标移上去但是并没有单击
((e.State&DrawItemState.Selected)DrawItemState.Selected)
{
//花边框和底色
g.FillRectangle(Brushes.LightSteelBlue,e.Bounds.X,e.Bounds.Y,109,20);
g.DrawLine(p,e.Bounds.X,e.Bounds.Y,e.Bounds.X,e.Bounds.Y+19);
g.DrawLine(p,e.Bounds.X,e.Bounds.Y+19,e.Bounds.X+109,e.Bounds.Y+19);
g.DrawLine(p,e.Bounds.X+109,e.Bounds.Y+19,e.Bounds.X+109,e.Bounds.Y);
g.DrawLine(p,e.Bounds.X+109,e.Bounds.Y,e.Bounds.X,e.Bounds.Y);
}
//显示文字
g.DrawString(this.Text,f,Brushes.Black,e.Bounds.X,e.Bounds.Y);
g.Dispose;
}
//这是很重要这给你菜单定义了大小高20宽100否则你菜单什么也看不到
protectedoverridevoidOnMeasureItem(MeasureItemEventArgse)
{
e.ItemHeight=20;
e.ItemWidth=100;
}
}
介绍说明:这里我没有画按钮按下时样子(懒:)主要是以后进步改进),当然也没有画图标也是为了以后改进这只是个初步形态大家看看有什么更高思路方法?!
最新评论