绘制圆角窗体和圆角panel

protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
            GraphicsPath oPath = new GraphicsPath();
            int x = 0;
            int y = 0;
            int w = Width;
            int h = Height;
            int a = 14;
            Graphics g = CreateGraphics();
            oPath.AddArc(x, y, a, a, 180, 90);
            oPath.AddArc(w - a, y, a, a, 270, 90);
            oPath.AddArc(w - a, h - a, a, a, 0, 90);
            oPath.AddArc(x, h - a, a, a, 90, 90);
            oPath.CloseAllFigures();
            Region = new Region(oPath);
}

在窗体之中重写OnPaint方法,就可以将窗体绘制为圆角窗体。
该方法也可以使用在panel的Paint事件中,使panel变为圆角。另一个方法就是创建一个组件,组件继承Panel,然后再组件之中重写OnPaint方法,之后调用新建的组件,也可以达到同样的效果

想找一个无人的角落发呆……
原文地址:https://www.cnblogs.com/rogation/p/2795042.html