Converting ToolBar to ToolStrip control and MouseHover not working

*爱你&永不变心* 提交于 2020-01-25 10:06:25

问题


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


来源:https://stackoverflow.com/questions/25203599/converting-toolbar-to-toolstrip-control-and-mousehover-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!