【问题标题】:How to change the back color of tool strip split button in windows form c#如何在windows窗体c#中更改工具条拆分按钮的背景颜色
【发布时间】:2012-07-07 10:32:08
【问题描述】:

如何在 windows 窗体应用程序中更改工具条拆分按钮的背景颜色。 背景颜色属性不起作用..这是设计器类中的代码..

        this.level.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128)))));
        this.level.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
        this.level.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
        this.autoToolStripMenuItem1,
        this.loadToolStripMenuItem1});
        this.level.Image = global::PACS.Properties.Resources.winlevel;
        this.level.ImageTransparentColor = System.Drawing.Color.Red;
        this.level.Margin = new System.Windows.Forms.Padding(1, 1, 1, 2);
        this.level.Name = "level";
        this.level.Size = new System.Drawing.Size(53, 43);
        this.level.Text = "Level";
        this.level.TextImageRelation = System.Windows.Forms.TextImageRelation.Overlay;
        this.level.Paint += new System.Windows.Forms.PaintEventHandler(this.Window_level_Paint);
        this.level.Click += new System.EventHandler(this.Window_level_Click);

【问题讨论】:

标签: c# winforms toolstripbutton


【解决方案1】:

默认情况下,它的 BackColor 属性不起作用: 根据这个 (ToolStripSplitButton BackColor does not work),请按照以下两个步骤操作:

1) 将 BackgroundImage 设置为有效图像。没关系。我使用 1 像素 x 1 像素 BMP 作为本地资源。

2) 将 BackgroundImageLayout 设置为无。这就是为什么你在上面使用什么图像并不重要。

结果:

【讨论】:

    【解决方案2】:

    您可以为toolstrip 使用自定义渲染器,您可以在此answer 中找到类似问题的示例。

    【讨论】:

      猜你喜欢
      • 2018-01-04
      • 2012-08-20
      • 1970-01-01
      • 2011-06-26
      • 2012-03-02
      • 2013-09-15
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多