我有一个大型的 winform 应用程序,我们正在努力修改外观。我将 System.Windows.Forms.Toolbar 替换为 System.Windows.Forms.ToolStrip 控件。我使用自定义渲染器来更改下拉箭头颜色。使用默认渲染器,我在工具条中获得鼠标悬停效果,但使用我的自定义渲染,它似乎不起作用。这是我的代码。
工具条初始化:为了阅读舒适,我删除了不必要的代码
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.toolStripDropDownButton1 = new System.Windows.Forms.ToolStripDropDownButton();
this.toolStrip1.ImageList = this.imageList1;
this.toolStrip1.ImageScalingSize = new System.Drawing.Size(55, 32);
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripDropDownButton1
});
this.toolStrip1.Renderer = new MyRenderer();
工具条下拉按钮:
this.toolStripDropDownButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.toolStripDropDownButton1.ImageIndex = 0;
this.toolStripDropDownButton1.Name = "toolStripDropDownButton1";
自定义渲染器
public class MyRenderer : ToolStripRenderer
{
protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e)
{
e.ArrowColor = Color.White;
base.OnRenderArrow(e);
}
}