问题描述
所以我在C#中有一个MenuStrip,我试图为此做一个深色主题,但是当我很好地按下下拉菜单的按钮时....
So I have a MenuStrip in C# which I am trying to do a darkish theme for, but when I press the button for the dropdown menu well....
有没有办法使它从白色变成另一种颜色?我似乎找不到办法。
Is there a way to make it go from white to another color? I can't seem to figure out a way to do it. This is probably my first time even customizing context menus.
推荐答案
您可以使用 MouseHover
和 MouseLeave
事件。这简单。只需执行以下步骤:
You could use MouseHover
and MouseLeave
event. It's easy. Just do the following steps:
-
我们有一个包含以下项目的表单:
为ToolStripMenuItem选择深色背景。在示例中,我为 fileToolStripMenuItem
选择了黑色
颜色。
Choose that dark backcolor for ToolStripMenuItem. I choosed black
color for fileToolStripMenuItem
in my example.
将其用于 MouseHover
事件:
private void fileToolStripMenuItem_MouseHover(object sender, EventArgs e)
{
fileToolStripMenuItem.BackColor = Color.White;
fileToolStripMenuItem.ForeColor =Color.Black;
}
将其用于 MouseLeave
事件:
private void fileToolStripMenuItem_MouseLeave(object sender, EventArgs e)
{
fileToolStripMenuItem.BackColor = Color.Black;
fileToolStripMenuItem.ForeColor = Color.White;
}
这篇关于在鼠标悬停时更改ToolStripItem的BackColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!