找到窗体的Paint事件,写入以下代码
[C#] 纯文本查看 复制代码 private void form1_Paint(object sender, PaintEventArgs e)
{
#region 圆形窗体
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();//创建一条线
path.AddEllipse(0, 0, Width, Height);//画一个椭圆 (x,y,宽,高)
Graphics g = CreateGraphics();//为窗体创建画布
g.DrawEllipse(new Pen(Color.Black, 2), 1, 1, Width - 2, Height - 2);//为画布画一个椭圆(笔,x,y,宽,高)
Region = new Region(path);//设置控件的窗口区域
#endregion
} |