• <bdo id='P3b2N'></bdo><ul id='P3b2N'></ul>
  1. <small id='P3b2N'></small><noframes id='P3b2N'>

    <legend id='P3b2N'><style id='P3b2N'><dir id='P3b2N'><q id='P3b2N'></q></dir></style></legend>
  2. <i id='P3b2N'><tr id='P3b2N'><dt id='P3b2N'><q id='P3b2N'><span id='P3b2N'><b id='P3b2N'><form id='P3b2N'><ins id='P3b2N'></ins><ul id='P3b2N'></ul><sub id='P3b2N'></sub></form><legend id='P3b2N'></legend><bdo id='P3b2N'><pre id='P3b2N'><center id='P3b2N'></center></pre></bdo></b><th id='P3b2N'></th></span></q></dt></tr></i><div id='P3b2N'><tfoot id='P3b2N'></tfoot><dl id='P3b2N'><fieldset id='P3b2N'></fieldset></dl></div>

      <tfoot id='P3b2N'></tfoot>

      Windows 10 风格的 ContextMenuStrip

      时间:2023-09-15

        <tbody id='MYf63'></tbody>
      • <bdo id='MYf63'></bdo><ul id='MYf63'></ul>

              <tfoot id='MYf63'></tfoot>

              • <small id='MYf63'></small><noframes id='MYf63'>

                <legend id='MYf63'><style id='MYf63'><dir id='MYf63'><q id='MYf63'></q></dir></style></legend>
                <i id='MYf63'><tr id='MYf63'><dt id='MYf63'><q id='MYf63'><span id='MYf63'><b id='MYf63'><form id='MYf63'><ins id='MYf63'></ins><ul id='MYf63'></ul><sub id='MYf63'></sub></form><legend id='MYf63'></legend><bdo id='MYf63'><pre id='MYf63'><center id='MYf63'></center></pre></bdo></b><th id='MYf63'></th></span></q></dt></tr></i><div id='MYf63'><tfoot id='MYf63'></tfoot><dl id='MYf63'><fieldset id='MYf63'></fieldset></dl></div>
                本文介绍了Windows 10 风格的 ContextMenuStrip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                有没有办法使用 Visual Studio 和 Windows 10 样式的窗体创建 ContextMenuStrip.我知道,可以更改它的渲染器以使其看起来像 Windows Vista、7 和 8.这就是我所做的:

                但我也想让它在 Windows 10 中看起来像这样:

                有没有办法使用 Windows 窗体来完成,或者应该以某种特殊的方式完成,使用 Metro 类等?

                解决方案

                您可以实现您的自定义

                ColorTable 代码:

                公共类 MyColorTable : ProfessionalColorTable{公共覆盖颜色 MenuItemBorder{得到{返回颜色.WhiteSmoke;}}公共覆盖颜色 MenuItemSelected{得到{返回颜色.WhiteSmoke;}}公共覆盖颜色 ToolStripDropDownBackground{得到{返回颜色.白色;}}公共覆盖颜色 ImageMarginGradientBegin{得到{返回颜色.白色;}}公共覆盖颜色 ImageMarginGradientMiddle{得到{返回颜色.白色;}}公共覆盖颜色 ImageMarginGradientEnd{得到{返回颜色.白色;}}}

                渲染器代码:

                公共类 MyRenderer : ToolStripProfessionalRenderer{公共 MyRenderer(): 基础(新的 MyColorTable()){}受保护的覆盖无效 OnRenderArrow(ToolStripArrowRenderEventArgs e){e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;var r = new Rectangle(e.ArrowRectangle.Location, e.ArrowRectangle.Size);r.Inflate(-2, -6);e.Graphics.DrawLines(Pens.Black, new Point[]{新点(r.Left,r.Top),新点(r.Right, r.Top + r.Height/2),新点(r.Left, r.Top+ r.Height)});}受保护的覆盖无效 OnRenderItemCheck(ToolStripItemImageRenderEventArgs e){e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;var r = new Rectangle(e.ImageRectangle.Location, e.ImageRectangle.Size);r.Inflate(-4, -6);e.Graphics.DrawLines(Pens.Black, new Point[]{新点(r.Left,r.Bottom - r.Height/2),新点(r.Left + r.Width/3,r.Bottom),新点(r.Right, r.Top)});}}

                表单加载代码:

                private void Form_Load(object sender, EventArgs e){this.contextMenuStrip1.Renderer = new MyRenderer();}

                Is there a way to create ContextMenuStrip using Visual Studio and Forms with Windows 10 style. I know, that its Renderer can be changed in order to have look like Windows Vista, 7 and 8. And that is what I made:

                But I also would like to make it look like this in Windows 10:

                Is there a way to do it using Windows Forms, or it should be done in some special way, using Metro classes etc?

                解决方案

                You can implement your custom Renderer and override OnRenderArrow and OnRenderItemCheck and pass your custom ColorTable to it. Then set it as Renderer of your ContextMenu.

                Code for ColorTable:

                public class MyColorTable : ProfessionalColorTable
                {
                    public override Color MenuItemBorder
                    {
                        get { return Color.WhiteSmoke; }
                    }
                    public override Color MenuItemSelected
                    {
                        get { return Color.WhiteSmoke; }
                    }
                    public override Color ToolStripDropDownBackground
                    {
                        get { return Color.White; }
                    }
                    public override Color ImageMarginGradientBegin
                    {
                        get { return Color.White; }
                    }
                    public override Color ImageMarginGradientMiddle
                    {
                        get { return Color.White; }
                    }
                    public override Color ImageMarginGradientEnd
                    {
                        get { return Color.White; }
                    }
                }
                

                Code for Renderer:

                public class MyRenderer : ToolStripProfessionalRenderer
                {
                    public MyRenderer()
                        : base(new MyColorTable())
                    {
                    }
                    protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e)
                    {
                        e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                        var r = new Rectangle(e.ArrowRectangle.Location, e.ArrowRectangle.Size);
                        r.Inflate(-2, -6);
                        e.Graphics.DrawLines(Pens.Black, new Point[]{
                        new Point(r.Left, r.Top),
                        new Point(r.Right, r.Top + r.Height /2), 
                        new Point(r.Left, r.Top+ r.Height)});
                    }
                
                    protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e)
                    {
                        e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                        var r = new Rectangle(e.ImageRectangle.Location, e.ImageRectangle.Size);
                        r.Inflate(-4, -6);
                        e.Graphics.DrawLines(Pens.Black, new Point[]{
                        new Point(r.Left, r.Bottom - r.Height /2),
                        new Point(r.Left + r.Width /3,  r.Bottom), 
                        new Point(r.Right, r.Top)});
                    }
                }
                

                Code for Form Load:

                private void Form_Load(object sender, EventArgs e)
                {
                    this.contextMenuStrip1.Renderer = new MyRenderer();
                }
                

                这篇关于Windows 10 风格的 ContextMenuStrip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:使用 DoubleBuffering 和 FormBorderStyle.None 在 Windows10 上重绘问题 下一篇:将新的 Microsoft Edge 添加到 Web 浏览器控件?

                相关文章

                <small id='Y3yti'></small><noframes id='Y3yti'>

              • <legend id='Y3yti'><style id='Y3yti'><dir id='Y3yti'><q id='Y3yti'></q></dir></style></legend><tfoot id='Y3yti'></tfoot>
                <i id='Y3yti'><tr id='Y3yti'><dt id='Y3yti'><q id='Y3yti'><span id='Y3yti'><b id='Y3yti'><form id='Y3yti'><ins id='Y3yti'></ins><ul id='Y3yti'></ul><sub id='Y3yti'></sub></form><legend id='Y3yti'></legend><bdo id='Y3yti'><pre id='Y3yti'><center id='Y3yti'></center></pre></bdo></b><th id='Y3yti'></th></span></q></dt></tr></i><div id='Y3yti'><tfoot id='Y3yti'></tfoot><dl id='Y3yti'><fieldset id='Y3yti'></fieldset></dl></div>

                    <bdo id='Y3yti'></bdo><ul id='Y3yti'></ul>