[英]How to change the background color of ToolStripItems?
When I add a ToolStripMenuItem
to a ContextMenuStrip
and then add a ToolStripComboBox
in it, the background color under the ToolStripComboBox
isn't blue.当我将ToolStripMenuItem
添加到ContextMenuStrip
然后在其中添加ToolStripComboBox
时, ToolStripComboBox
下的背景颜色不是蓝色。 However, as you can see it's blue under 'Sub opt2' (which is in the main options of ContextMenuStrip
).但是,您可以在“Sub opt2”(位于ContextMenuStrip
的主要选项中)下看到它是蓝色的。
My question: How can you change the background that's underneath the ToolStripComboBox
?我的问题:如何更改ToolStripComboBox
下方的背景?
The Image below is an example of the these two ToolStripComboBox
having different background colors:下图是这两个具有不同背景 colors 的ToolStripComboBox
的示例:
The Image below is an example of the background color I want to change:下图是我要更改的背景颜色的示例:
Assume your Sub opt1
ToolStripMenuItem is named options1ToolStripMenuItem
:假设您的Sub opt1
ToolStripMenuItem 被命名为options1ToolStripMenuItem
:
you can remove the margin reserved to the Image, casting its DropDown
(which is of type ToolStripDropDown
) to ToolStripDropDownMenu
:您可以删除为图像保留的边距,将其DropDown
(类型为ToolStripDropDown
)转换为ToolStripDropDownMenu
:
(options1ToolStripMenuItem.DropDown as ToolStripDropDownMenu).ShowImageMargin = false;
Using the same logic, you can also set the BackColor of the DropDown (not the BackColor of single ToolStripItems
. If you change the BackColor of a ToolStripComboBox , as in this case, you just change the property value of the Control itself):使用相同的逻辑,您还可以设置 DropDown 的 BackColor (不是单个ToolStripItems
的 BackColor 。如果您更改ToolStripComboBox的 BackColor ,在这种情况下,您只需更改 Control 本身的属性值):
options1ToolStripMenuItem.DropDown.BackColor = [Your Color];
You can add this code to the Form's Constructor.您可以将此代码添加到表单的构造函数中。
You need to repeat the same operation to configure other sub-menus.您需要重复相同的操作来配置其他子菜单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.