如何在winform中绘制圆角形状?

时间:2015-11-26 08:16:25

标签: c# winforms

不重复,请正确阅读问题并标记重复

我想使用C#绘制圆角winform。

我能够绘制它,但它不是在角落绘制边框。

我使用了以下代码。

private void OnPaint(object sender, PaintEventArgs e) {

            Pen DrawPen = new Pen(Color.Black);
            GraphicsPath gfxPath_mod = new GraphicsPath();

            int top = 0;
            int left = 0;
            int right = Width;
            int bottom = Height;
            int CornerRadius = 18;

            gfxPath_mod.AddArc(left, top, CornerRadius, CornerRadius, 180, 90);
            gfxPath_mod.AddArc(right - CornerRadius, top, CornerRadius, CornerRadius, 270, 90);
            gfxPath_mod.AddArc(right - CornerRadius, bottom - CornerRadius, 
                    CornerRadius, CornerRadius, 0, 90);
            gfxPath_mod.AddArc(left, bottom - CornerRadius, CornerRadius, CornerRadius, 90, 90);

            e.Graphics.DrawArc(DrawPen, left, top, CornerRadius, CornerRadius, 180, 90);
            e.Graphics.DrawArc(DrawPen, right - CornerRadius, top, CornerRadius, CornerRadius, 270, 90);
            e.Graphics.DrawArc(DrawPen, right - CornerRadius, bottom - CornerRadius, 
                    CornerRadius, CornerRadius, 0, 90);
            e.Graphics.DrawArc(DrawPen, left, bottom - CornerRadius, CornerRadius, CornerRadius, 90, 90);
            gfxPath_mod.CloseAllFigures();

            e.Graphics.DrawPath(DrawPen, gfxPath_mod);           

            this.Region = new System.Drawing.Region(gfxPath_mod);
    }

0 个答案:

没有答案