首先介紹下圓弧的構造
首先引用
using System.Drawing;
using System.Drawing.Drawing2D;
C# GraphicsPath.AddArc 方法 (Int32, Int32, Int32, Int32, Single, Single)問題
4個int分別表示矩形的左上角X,Y坐標,矩形的寬和高,C#里面畫的橢圓的大小是用矩形來定義的,你定義矩形后,繪制的就是矩形的內切橢圓,后面兩個為起始角度和終止角度。以橢圓弧為中心的極坐標系,正左端為0°,度數逆時針增加,起始角度就是指定弧的起點端點,終止角度就是另一個端點.譬如,起始角度為90°,終止角度為180°,就是右下角的四分之一橢圓
然后重寫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;
}
改善后的圖片如下:
