我使用 ToolStripDropDownButton,Forecolor 是白色,Backcolor 是透明。当鼠标位于控件上方时,“ToolStripDropDownButton”的文本不可读,因为“蓝色焦点”可见。
当鼠标在控件上方时,如何消除/移除 ToolStripDropDownButton 上的“blue focus”?看起来像下图。谢谢。
产生像 digEmAll 图片这样的输出。
using System;
using System.Windows.Forms;
using System.Drawing;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
toolStrip1.BackColor = Color.Transparent;
toolStrip1.GripStyle = ToolStripGripStyle.Visible;
toolStrip1.Renderer = new MyRenderer();
}
private class MyRenderer : ToolStripSystemRenderer
{
protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e)
{
e.ArrowColor = Color.White;
base.OnRenderArrow(e);
}
protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
{
// remove white line bellow button (http://connect.microsoft.com/VisualStudio/feedback/details/92862/toolstrip-always-draws-a-border-on-the-bottom-with-rendermode-system-and-docked-left-or-right)
//base.OnRenderToolStripBorder(e);
}
}
}
}
最佳答案
您可以重新分配 ToolStrip 的 Renderer 属性以创建您自己的渲染器。然而,重写 OnRenderSplitButtonBackground() 非常痛苦,拆分按钮有很多需要绘制的装饰物,而且库存绘制器方法是私有(private)的。在您的情况下,更简单的方法是覆盖颜色表。让它看起来像这样:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
toolStrip1.Renderer = new MyRenderer();
}
private class MyRenderer : ToolStripProfessionalRenderer {
public MyRenderer() : base(new MyColors()) {}
}
private class MyColors : ProfessionalColorTable {
public override Color ButtonSelectedGradientBegin {
get { return Color.Black; }
}
public override Color ButtonSelectedGradientMiddle {
get { return Color.Black; }
}
public override Color ButtonSelectedGradientEnd {
get { return Color.Black; }
}
}
}
关于c# - 当鼠标在控件上方时如何消除 ToolStripDropDownButton 上的蓝色焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10053867/