110,533
社区成员
发帖
与我相关
我的任务
分享
private int Round = 8;
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e); //这里会绘image属性图片
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
DrawFormBorder(e.Graphics);
}
// 画边框
public void DrawFormBorder(Graphics g)
{
using(GraphicsPath formBorderPath = new GraphicsPath())
{
formBorderPath.AddArc(0, 0, Round, Round, 180, 90);
formBorderPath.AddArc(Width - Round - 1, 0, Round, Round, 270, 90);
formBorderPath.AddArc(Width - Round - 1, Height - Round - 1, Round, Round, 0, 90);
formBorderPath.AddArc(0, Height - Round - 1, Round, Round, 90, 90);
formBorderPath.CloseAllFigures();
using(Pen pen = new Pen(Color.Black))//这里可以改变边框的宽度 pen.Width
{
g.DrawPath(pen, formBorderPath);
}
}
}
//控件大小改变后 重新划定空间区域
protected override void OnResize(System.EventArgs e)
{
base.OnResize(e);
using(GraphicsPath formBorderPath = new GraphicsPath())
{
formBorderPath.AddArc(0, 0, Round, Round, 180, 90);
formBorderPath.AddArc(Width - Round, 0, Round, Round, 270, 90);
formBorderPath.AddArc(Width - Round, Height - Round, Round, Round, 0, 90);
formBorderPath.AddArc(0, Height - Round, Round, Round, 90, 90);
formBorderPath.CloseAllFigures();
this.Region = new Region(formBorderPath);
}
this.Invalidate(true);
}