winforms 如何处理ContextMenuStrip属性,特别是边框颜色

dsekswqp  于 2022-12-14  发布在  其他
关注(0)|答案(1)|浏览(240)

如何处理ContextMenuStrip属性,特别是边框颜色???
C#中的任何方法或使用Windows API(DllImport)的任何方法?

qvtsj1bj

qvtsj1bj1#

可以创建自定义颜色表并更改渲染器属性:

public class MenuColorTable : ProfessionalColorTable
{
    public MenuColorTable()
    {
        UseSystemColors = false;
    }
    public override Color MenuBorder
    {
        get { return Color.Fuchsia; }
    }
    public override Color MenuItemBorder
    {
        get { return Color.DarkViolet; }
    }
    public override Color MenuItemSelected
    {
        get { return Color.Cornsilk; }
    }
    public override Color MenuItemSelectedGradientBegin
    {
        get { return Color.LawnGreen; }
    }
    public override Color MenuItemSelectedGradientEnd
    {
        get { return Color.MediumSeaGreen; }
    }
    public override Color MenuStripGradientBegin
    {
        get { return Color.AliceBlue; }
    }
    public override Color MenuStripGradientEnd
    {
        get { return Color.DodgerBlue; }
    }
}

变更Renderer

contextMenuStrip1.Renderer = new ToolStripProfessionalRenderer(new MenuColorTable());

结果如下:

相关问题