C#winform去除btn按钮的边框

系统自带的按钮无法去除边框。网上找了个解决方案:

重写按钮的OnPaint事件

    class newbtn : System.Windows.Forms.Button //继承之系统按钮控件  
{
protected override void OnPaint(PaintEventArgs e)
{//重写

base.OnPaint(e);
System.Drawing.Pen pen = new Pen(this.BackColor, 3);
e.Graphics.DrawRectangle(pen, 0, 0, this.Width, this.Height);//填充
pen.Dispose();

}
}

 

然后将designer。cs文件中你要修改的按钮重新继承至newbtn就可。

你可能感兴趣的:(WinForm)