1.用Windows API(费事、效果不好)
2.强烈推荐用Active Bar2.0 SP3(XP风格、功能强大。想要的话留下Mail)
3.用其它控件。
2.强烈推荐用Active Bar2.0 SP3(XP风格、功能强大。想要的话留下Mail)
3.用其它控件。
解决方案 »
- webbrowser控件 未将对象引用设置到对象的实例 坐等..
- 急!!急!!急!!急!!在线等!!!!!(Window Service问题)
- 一个很简单的问题!
- VS2005 做的Web程序发布到XP的IS中为什么报错说找不到Oracle客户端?
- 求助啊,socket编程,TCP网络传消息
- 在发送mail中,如何把单发改为群发,且邮件内容是变化的(SOCKET)?
- 初学c#,做个个人主页,大家评一下,采用web Service
- C#英文怎么读? 还有C,C++,C#有啥区别?(附上我所有的分了)
- 如何用一个字符串数组动态调用参数方式执行的SQL语句?
- iis6.0转iis7.0后报错。
- 控件的布局问题
- C#的多线程编程
http://www30.brinkster.com/zhaixd/column.asp?includeurl=source/code.asp
首先,需设置该菜单项,如menuItemExit菜单项的OwnerDraw属性为true;
然后,需要处理menuItemExit菜单项的MeasureItem事件的响应方法menuItemExit_MeasureItem(object sender, System.Windows.Forms.MeasureItemEventArgs e)和该菜单项的DrawItem事件的响应方法private void menuItemExit_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)。
其中:
MeasureItem:用于设置菜单项的高度和宽度;
DrawItem:用来绘制实际的菜单项,包括图标,文本等等。
下面提供一段示例代码,用来实现加图标exit.bmp的菜单项menuItemExit,可供您参考:
private void menuItemExit_MeasureItem(object sender, System.Windows.Forms.MeasureItemEventArgs e)
{
e.ItemHeight = 25;
e.ItemWidth = 75;
}private void menuItemExit_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
Rectangle rc = new Rectangle(e.Bounds.X,e.Bounds.Y,e.Bounds.Width,e.Bounds.Height);
e.Graphics.FillRectangle(new SolidBrush(Color.White),rc);
MenuItem s = (MenuItem)sender;
string strItem = s.Text;
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Far;
sf.LineAlignment = StringAlignment.Center;
e.Graphics.DrawString(strItem,new Font("Veranda",10), new SolidBrush(Color.Blue),rc,sf);
e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.White)),rc);
if(e.State ==(DrawItemState.NoAccelerator | DrawItemState.Selected))
{
e.Graphics.FillRectangle(new SolidBrush(Color.CornflowerBlue),rc);
e.Graphics.DrawString(strItem,new Font("Veranda",10,FontStyle.Bold|FontStyle.Underline),new SolidBrush(Color.Yellow),rc,sf);
e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.Blue)),rc);
//Draws a focus rectangle within the bounds specified in the DrawItemEventArgs constructor.
e.DrawFocusRectangle();
} Image imgExit = new Bitmap("exit.bmp");
SizeF sz = imgExit.PhysicalDimension ;
e.Graphics.DrawImage(imgExit,e.Bounds.X + 5,(e.Bounds.Bottom + e.Bounds.Top)/2 - sz.Height/2);
}
— 微软全球技术中心 VB支持中心本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。