C#为对话框form添加圆弧拐角

首先介绍下圆弧的构造

首先引用

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;
  
        }
改善后的图片如下:




你可能感兴趣的:(C#,对话框美化,圆弧拐角)