简体   繁体   English

尝试为 MenuStrip 着色,左侧出现白色边框

[英]Trying to color a MenuStrip, a white border appears on the left side

I'm creating a Form and I want the menu bar to have different colors.我正在创建一个表单,我希望菜单栏有不同的 colors。 There are many posts on this, I've managed to alter all the colors, except for a white block/line down the left hand side of the menu.有很多关于此的帖子,我已经设法更改了所有 colors,除了菜单左侧的白色块/线。
I'm using.Net Core 3.1, Windows Forms application.我正在使用.Net Core 3.1,Windows Forms 应用程序。

在此处输入图像描述

The white block behind the Exit ToolstripMenuItem: it becomes wider when a Separator is used. Exit ToolstripMenuItem 后面的白色块:使用 Separator 时会变宽。

在此处输入图像描述

Thin white line on the above menus.上述菜单上的细白线。

I'm using a professional renderer to override the colors.我正在使用专业渲染器来覆盖 colors。

public class DxColorTable : ToolStripProfessionalRenderer
{
    public DxColorTable(dynamic theme) : base(new DxCols(theme)) { }
}

public class DxCols : ProfessionalColorTable
{
    private readonly dynamic theme = DefaultTheme.Default;
    public DxCols(dynamic theme)
    {
        this.theme = theme;
    }

    public override Color MenuBorder
    {
        get { return this.theme.MenuSelectedColor; }
    }
    public override Color MenuItemBorder
    {
        get { return this.theme.MenuSelectedColor; }
    }
    public override Color MenuItemPressedGradientBegin
    {
        get { return this.theme.MenuSelectedColor; }
    }

    public override Color MenuItemPressedGradientEnd
    {
        get { return this.theme.MenuSelectedColor; }
    }
    public override Color MenuItemSelected
    {              
        get { return this.theme.MenuSelectedColor; }
    }
    public override Color MenuItemSelectedGradientBegin
    {            
        get { return this.theme.MenuSelectedColor; }
    }
    public override Color MenuItemSelectedGradientEnd
    {
        get { return this.theme.MenuSelectedColor; }
    }

    public override Color ToolStripBorder
    {
        get { return this.theme.MenuBackgroundColor; }
    }
    
    public override Color ToolStripDropDownBackground
    {
        get { return this.theme.MenuBackgroundColor; }
    }
    public override Color ToolStripGradientBegin
    {
        get { return this.theme.MenuBackgroundColor; }
    }
    public override Color ToolStripGradientEnd
    {
        get { return this.theme.MenuBackgroundColor; }
    }
    public override Color ToolStripGradientMiddle
    {
        get { return this.theme.MenuBackgroundColor; }
    }

    public override Color ToolStripContentPanelGradientBegin
    {
        get
        {
            return this.theme.MenuBackgroundColor; 
        }
    }

    public override Color ToolStripContentPanelGradientEnd
    {
        get
        {
            return this.theme.MenuBackgroundColor;
        }
    }
}

You forgot to override the three properties that define the Image margin area.您忘记覆盖定义图像边距区域的三个属性。
You need to specify a Color value for the ImageMarginGradient part.您需要为ImageMarginGradient部分指定一个 Color 值。

It's particularily visible when you add a ToolStripComboBox or a ToolStripSeparator.当您添加 ToolStripComboBox 或 ToolStripSeparator 时,它尤其明显。 Note that it doesn't affect standard ToolStripMenuItems, even when these show an Image, when a Background Color has already been set in the designer.请注意,它不会影响标准 ToolStripMenuItems,即使它们显示图像,并且已经在设计器中设置了背景颜色。

public override Color ImageMarginGradientBegin => this.theme.MenuBackgroundColor;
public override Color ImageMarginGradientMiddle => this.theme.MenuBackgroundColor;
public override Color ImageMarginGradientEnd => this.theme.MenuBackgroundColor; 

If you don't need to show Images, you can hide the Image margin area:如果不需要显示图片,可以隐藏图片边距区域:

([Your ToolStripMenuItem].DropDown as ToolStripDropDownMenu).ShowImageMargin = false; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM