奇简单的问题,给菜单加一个图标? 要实现这个功能.必须将菜单的OwnerDraw属性设置为true,然后自已绘制. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 设置菜单属性为重绘 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(); } 同意 haiwangstar(南河三(来自于小犬星座)) 这一点delphi实现的话要方便 clickonce 清单签名 过期,有没有延长时间的方法 刷新combox 一个传入对象的问题 想看电影的请进 vsdotnet2005的crystalreportview运行系统总是提示“您请求的报表需要更多的信息” MDI问题 在水晶报表中设置当前表的连接信息 请教这个linq分组求和的写法? 反射如何用dll中的类? 请教关于mshtml.IHTMLDOMNode的attributes属性如何使用的! 运行C#应用程序需要什么环境? 怎样在PropertyGrid显示一些特定的属性?
/// <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();
}
这一点delphi实现的话要方便