c#WinForm:删除或自定义按钮的“对焦矩形”

有没有办法禁用或更好地绘制自己的焦点矩形为常规的按钮控件! (虚线似乎是 Windowss 95ish)

我注意到,控件属性(FOR BUTTONS)没有ownerdrawfixed设置(我不知道这甚至是用于解决方案的路径,尽管我已经看到它用于自定义其他控件).

解决方法

得到这个权利比听起来更棘手.毫无疑问,自定义按钮绘画不可覆盖的原因之一.这样工作如预期:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;

class MyButton : Button {
    private VisualStyleRenderer renderer;
    protected override void OnPaint(PaintEventArgs e) {
        base.OnPaint(e);
        if (this.Focused && Application.RenderWithVisualStyles && this.FlatStyle == FlatStyle.Standard) {
            if (renderer == null) {
                VisualStyleElement elem = VisualStyleElement.Button.PushButton.normal;
                renderer = new VisualStyleRenderer(elem.ClassName,elem.Part,(int)PushButtonState.normal);
            }
            Rectangle rc = renderer.GetBackgroundContentRectangle(e.Graphics,new Rectangle(0,this.Width,this.Height));
            rc.Height--;
            rc.Width--;
            using (Pen p = new Pen(Brushes.DarkGray)) {
                e.Graphics.DrawRectangle(p,rc);
            }
        }
    }
}

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...