ele*_*l09 6 c# button highlight visual-studio mousehover
I found this page, which outlines how to change the rendering for a MenuStrip and its items.
I want to use this, but the problem is that the highlight color when you hover over a button doesn't match it.
Is there any way to change the highlight color from blue to yellow? I've tried using the MouseHover and MouseLeave events, but for some reason they're really slow, and they change the button to a solid color, which looks bad, but leaves a border on the edge of the button that doesn't change.
In the designer:
this.ButtonName.MouseHover += new System.EventHandler(button_mousehover);
Run Code Online (Sandbox Code Playgroud)
And then in the Code:
private void button_mousehover(object sender, EventArgs e)
{
Button btn = sender as Button;
btn.BackColor = Color.Yellow;
}
Run Code Online (Sandbox Code Playgroud)
Is there anything as easy as in the link I posted above to change the highlight color from blue to something else?
Here's the code for changing the rendering of the menu strip:
private void myForm Load(object sender, EventArgs e)
{
myMenuStrip.Renderer = new MenuRenderer();
{
private class MenuRenderer : ToolStripProfessionalRenderer
{
public MenuRenderer() : base(new MyColors()) { }
}
private class MyColors : ProfessionalColorTable
{
public override Color MenuItemSelectedGradientBegin
{
get { return Color.Orange; }
}
public override Color MenuItemSelectedGradientEnd
{
get { return Color.Yellow; }
}
public override Color MenuItemPressedGradientBegin
{
get{ return Color.Yellow; }
}
public override Color MenuItemPressedGradientEnd
{
get { return Color.Orange; }
}
public override Color MenuItemSelected
{
get { return Color.Gold; }
}
}
Run Code Online (Sandbox Code Playgroud)
So it'll change the background of a hovered-over menu item to an orange-yellow gradient, change it to a yellow-orange gradient on click, and any item in the menu will have a gold highlight on hovering.
What I'm trying to do is do that last part (change the highlight to gold/yellow) for the buttons in my form.
Chu*_*que 12
在按钮的属性中:
在 下FlatStyle,选择Flat。
然后,展开FlatAppearance并在 下MouseOverBackColor,选择您想要的高亮颜色。或者,您也可以RGB color在MouseOverBackColor.
您可以看一下按钮渲染器。
当您可以简单地订阅 MouseHover 事件时,为什么要重写渲染器,如下所示:
this.someButtonName.MouseHover += (s,e) =>
{
this.someButtonName.BackColor = Color.Yellow;
};
Run Code Online (Sandbox Code Playgroud)
我建议您也使用鼠标离开按钮,以便在鼠标不再位于按钮上时将按钮重置为其初始颜色。
| 归档时间: |
|
| 查看次数: |
24962 次 |
| 最近记录: |