本文主要是介绍C#为对话框form添加圆弧拐角,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
首先介绍下圆弧的构造
首先引用
using System.Drawing;
using System.Drawing.Drawing2D;
然后重写OnCreateControl方法,将如下代码放在界面文件X.cs中即可,不是X.designer.cs
protected override void OnCreateControl()
{
base.OnCreateControl();
int rad = 4;
GraphicsPath path = new GraphicsPath();
path.AddArc(0, 0, rad, rad, 90, 180);
path.AddLine(rad, 0, this.Size.Width - rad, 0);
path.AddArc(this.Size.Width, 0, rad, rad, 180, 270);
path.AddLine(this.Size.Width, rad, this.Size.Width, this.Size.Height - rad);
path.AddArc(this.Size.Width - rad, this.Size.Height - rad, rad, rad, 90, 180);
path.AddLine(this.Size.Width - rad, this.Size.Height, rad, this.Size.Height);
path.AddArc(0, this.Size.Height, rad, rad, 180, 90);
path.AddLine(0, this.Size.Height - rad, 0, rad);
Region region = new Region(path);
region.Union(path);
this.Region = region;
}
{
base.OnCreateControl();
int rad = 4;
GraphicsPath path = new GraphicsPath();
path.AddArc(0, 0, rad, rad, 90, 180);
path.AddLine(rad, 0, this.Size.Width - rad, 0);
path.AddArc(this.Size.Width, 0, rad, rad, 180, 270);
path.AddLine(this.Size.Width, rad, this.Size.Width, this.Size.Height - rad);
path.AddArc(this.Size.Width - rad, this.Size.Height - rad, rad, rad, 90, 180);
path.AddLine(this.Size.Width - rad, this.Size.Height, rad, this.Size.Height);
path.AddArc(0, this.Size.Height, rad, rad, 180, 90);
path.AddLine(0, this.Size.Height - rad, 0, rad);
Region region = new Region(path);
region.Union(path);
this.Region = region;
}
改善后的图片如下:
这篇关于C#为对话框form添加圆弧拐角的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!