有谁知道我是否以及如何能够通过 Visual Studio 2008 中的简单下拉菜单更改图像条的颜色? 目前,通过下拉菜单,我有自己的项目集合,下拉菜单上的每个项目旁边都有一个图像条,目前是灰色,具有从浅到深的渐变。 我很想知道这种颜色是否可以改变或完全删除?
提前谢谢大家,克雷格。
Does anyone know if, and how I am able to change the colour of the image strip on a simple drop down in visual studio 2008? Currently with a drop down menu i have my own collectn of items, and beside each on the drop down menu is an image strip, which is curently a grey colour with a light to dark gradient. I am eager to find out if this colour can be changed or possibly removed altogether?
Thanks in advance guys, Craig.
发布评论
评论(2)
您可以通过创建 ToolStripRenderer 的子类并重写适当的渲染方法来实现此行为。 有关示例,请参阅 MSDN。
我假设您正在寻找 WinForms 解决方案。 对于 WPF/Xaml,解决方案当然完全不同,可以通过更改控件模板来完成。
You can realize this behavior by creating a subclass of ToolStripRenderer and overriding the appropriate rendering methods. See MSDN for examples.
I am assuming you are looking for a WinForms solution. For WPF/Xaml the solution is of course completely different and can be accomplished by changing the control templates.
我假设你问的是 winforms,因为我不了解 WPF。
如果您只想隐藏图像条,可以设置
ShowImageMargin
和ShowCheckMargin
属性设置为 false。 但是,您将无法显示菜单项的图像。至少在 XP 上,设置
属性将为您提供一个没有任何图像边距装饰的菜单; 尽管它可能与您的应用程序的视觉风格不匹配。
ToolStripRenderMode.System
下拉列表的 RenderMode如果您为每个菜单项设置
BackColor
,则图像边距将被遮挡。要隐藏图像边距而不更改下拉列表的视觉样式,您需要创建一个带有空
OnRenderImageMargin
函数,如下所示:然后设置下拉列表的
Renderer
属性到新渲染器类的实例。 您可以通过修改渲染器的ColorTable
以类似的方式更改图像边距的颜色。但是,在执行这些操作之前,请先问问自己:
第一个问题的答案通常是“否”。
I'm going to assume you're asking about winforms, as I don't know about WPF.
If you just want to hide the image strip, you can set the
ShowImageMargin
andShowCheckMargin
properties to false. However, you won't be able to display images for your menu items.On XP at least, setting the
RenderMode
property of the dropdown toToolStripRenderMode.System
will give you a menu without any image margin decoration; though it may not match the visual style of your application.If you set a
BackColor
for each of your menu items, the image margin will be obscured.To hide the image margin without changing the visual style of the dropdown, you'll need to create a renderer with an empty
OnRenderImageMargin
function, like so:and then set the dropdown's
Renderer
property to an instance of the new renderer class. You could change the colour of the image margin in a similar manner by modifying the renderer'sColorTable
.But, before you do any of those, ask yourself:
The answer to the first question is usually 'No'.