-->

Converting ToolBar to ToolStrip control and MouseH

2019-09-06 15:05发布

问题:

I have a large winform application which we working to modify the appearance. I am replacing System.Windows.Forms.Toolbar to System.Windows.Forms.ToolStrip control. I use a custom renderer to change dropdown arrow color. with default renderer i get mouse hover effects in toolstrip but with my custom rendering it dont seem to work. Here's my code.

Tool strip initialization:I removed unnecessary code for reading comfort

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();

Toolstrip dropdown button:

 this.toolStripDropDownButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
 this.toolStripDropDownButton1.ImageIndex = 0;
 this.toolStripDropDownButton1.Name = "toolStripDropDownButton1";

CustomRenderer

 public class MyRenderer : ToolStripRenderer
 {
    protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e)
    {
        e.ArrowColor = Color.White;
        base.OnRenderArrow(e);
    }
 }

回答1:

thanks to @LarsTech for his help. I found this working. I made this below modification in renderer and in code.

Added this line in initialization

this.Toolstip1.RenderMode = ToolStripRenderMode.Professional;

CustomRenderer

public class MyRenderer : ToolStripProfessionalRenderer //Professional renderer
{
   protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e)
   {
    e.ArrowColor = Color.White;
    base.OnRenderArrow(e);
   }
 }