窗休上有个按钮,我想让他由始于终都不显示虚边框,
在网上找到一段代码
class myButton : System.Windows.Forms.Button
    {
        protected override bool ShowFocusCues
        {
            get
            {
                // 获得焦点的时候什么都不做   
                return false;
            }
        }
    }当前窗体为活动状态时,按钮是不会显示虚边框,
但是再打开其他程序,按钮又显示虚边框,
怎么样当窗体为非活动状态时按钮也不显示虚边框???

解决方案 »

  1.   

    你好,希望可以帮助你.
    在样式里,设置
    border:0;
      

  2.   

     private void button2_Paint(object sender, PaintEventArgs e)
            {
                Graphics g = e.Graphics;
                RectangleF ref1 = button2.DisplayRectangle;
                g.FillRectangle(new SolidBrush(Color.BlanchedAlmond),ref1);
                g.DrawString("button3", new Font("宋体", 10), new SolidBrush(Color.Black), ref1.Left+ref1.Width/5,ref1.Top+ref1.Height/5,StringFormat.GenericTypographic);
            }
    类似这样 其他的楼主可看着自己调整吧~
      

  3.   

    不要边框?那你就愣个label,加个OnClick事件,不就完了么
      

  4.   

    public class MyButton: ButtonBase, IButtonControl
    {
       重写 OnPaint
    }
      

  5.   

    窗体不要边框我就会 呵呵呵    button不要我就没听过  
      

  6.   

    属性里面的 ForeColor 颜色调成和背景色一样。
      

  7.   

    提供个例子,剩下的自己画
    using System;
    using System.Windows.Forms;
    using System.Drawing;public class CustomButtom : ButtonBase, IButtonControl
    {
        private DialogResult _DialogResult;    public CustomButtom()
        {
        }    #region 基类和接口的实现    public DialogResult DialogResult
        {
            get
            {
                return this._DialogResult;
            }        set
            {
                if (Enum.IsDefined(typeof(DialogResult), value))
                {
                    this._DialogResult = value;
                }
            }
        }
        public void NotifyDefault(bool value)
        {
            if (this.IsDefault != value)
            {
                this.IsDefault = value;
            }
        }
        public void PerformClick()
        {
            if (this.CanSelect)
            {
                this.OnClick(new EventArgs());
            }
        }    #endregion    string msState = "";    protected override void OnMouseEnter(EventArgs eventargs)
        {
            base.OnMouseEnter(eventargs);
            this.msState = "enter";
        }    protected override void OnMouseLeave(EventArgs eventargs)
        {
            base.OnMouseLeave(eventargs);
            this.msState = "leave";
        }    protected override void OnMouseDown(MouseEventArgs mevent)
        {
            base.OnMouseDown(mevent);
            this.msState = "down";
        }    protected override void OnMouseUp(MouseEventArgs mevent)
        {
            base.OnMouseUp(mevent);
            this.msState = "up";
            this.Refresh();
        }    protected override void OnPaint(PaintEventArgs e)
        {
            // base.OnPaint(e);        Graphics g = e.Graphics;        Color bg = this.BackColor;
            Color fg = this.ForeColor;        switch (this.msState)
            {
                case "enter":
                    bg = Color.LightSkyBlue;
                    break;
                case "down":
                    bg = Color.SteelBlue;
                    fg = Color.White;
                    break;
                case "up":                Console.WriteLine(
                        this.RectangleToScreen(
                        this.ClientRectangle).Contains(
                        Cursor.Position.X, Cursor.Position.Y));                if (this.RectangleToScreen(
                        this.ClientRectangle).Contains(
                        Cursor.Position.X, Cursor.Position.Y))
                    {
                        bg = Color.LightSkyBlue;
                    }
                    break;
            }        g.Clear(bg); // 背景        // 绘制边框
            g.DrawRectangle(Pens.SteelBlue,
                0, 0, this.Width - 1, this.Height - 1);        // 绘制默认按钮边框
            if (this.IsDefault)
            {
                g.DrawRectangle(Pens.LightSalmon,
                    1, 1, this.Width - 3, this.Height - 3);
            }        // 绘制焦点边框
            if (this.Focused)
            {
                ControlPaint.DrawFocusRectangle(g,
                    new Rectangle(4, 4, this.Width - 7, this.Height - 7));
            }        using (Brush b = new SolidBrush(fg))
            {
                // 计算 Text 的 SizeF
                SizeF sf = g.MeasureString(this.Text, this.Font);
                float x = (g.ClipBounds.Width - sf.Width) / 2.0f;
                float y = (g.ClipBounds.Height - sf.Height) / 2.0f;            // 绘制文本
                g.DrawString(this.Text, this.Font, b, x, y);
            }
        }
    }
      

  8.   

    两种方法:
    1 程序在VISTA/WIN7上运行不会出现焦点框
    2 不使用自带Button控件而使用Label等无焦点框控件代替.