如何删除 MenuStrip 控件下绘制的白线?
我读了一些其他文章,了解人们如何自定义 MenuStrip 的颜色和渐变。
我想要做的是删除渐变,以便 MenuStrip 与表单的其余部分具有相同的颜色,对我来说,这是创建新的 WinForms 项目时使用的默认设置。我尝试将 RenderMode 更改为“System”,它可以正常工作,但是当我构建并运行它时,它会留下一条与 MenuStrip 的长度相同的白线。我必须做一些绘画吗?或者有更简单的方法吗?
I read a few other articles about how people want to customize the colors and gradients of a MenuStrip.
What I want to do is remove the gradient so that the MenuStrip is the same color as the rest of the form which, for me, is the default settings used when creating a new WinForms project. I tried changing the RenderMode
to 'System' and it works sort of, but it leaves a white line the length of the MenuStrip when I build and run it. Do I have to do some drawing and painting? Or is there an easier way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这基本上与这个一个< /a>
答案引用了这个Microsoft bug post
这似乎是从 2005 年开始就一直存在的问题。尽管评论说这是一个 MS bug,无法修复,有一种解决方法涉及实现您自己的渲染器:
然后您所要做的就是将菜单条的渲染器设置为您刚刚实现的渲染器:
我刚刚尝试了一下,它似乎工作得很好。
This is basically the same question as this one
The answer references this Microsoft bug post
It seems to be an issue all the way from 2005. Although the comments say that it is a MS bug which will not be fixed, there is a workaround which involves implementing your own renderer:
Then all you have to do is set your menustrip's renderer to the one you just implemented:
I just tried it out and it seems to work just fine.
我同意 Yetti 的观点,但如果你想维持你的边界,你可以尝试这个。将画笔替换为您的背景颜色
I agree with Yetti but if you wish to maintain your borders you can try this. Replace Brush with your background Color
@Yetti 的答案是正确的,但有一个小问题。它还删除了菜单下拉部分(单击某个项目时打开的菜单)的边框。为了避免这种情况,请在 OnRenderToolStripBorder 中执行以下操作:
@Yetti's answer is correct, but has a small issue. It also removes the border from the dropdown part of the menu (the one that opens when you click on an item). In order to avoid this, do the following in OnRenderToolStripBorder: