Rounding The Edges Of Your Form C#

By sbondo1234 on 29 June, 2019

Step 1 - The Importing

using System.Runtime.InteropServices;
using System.Drawing;

Put this one inside of your class:

[DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
private static extern IntPtr CreateRoundRectRgn
(
    int nLeftRect,     // x-coordinate of upper-left corner
    int nTopRect,      // y-coordinate of upper-left corner
    int nRightRect,    // x-coordinate of lower-right corner
    int nBottomRect,   // y-coordinate of lower-right corner
    int nWidthEllipse, // height of ellipse
    int nHeightEllipse // width of ellipse
);

Step 2 - Rounding

I would put this in the initialisation of your form.

this.FormBorderStyle = FormBorderStyle.None; //<– if it isn’t already!
Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20));

Done!

On this specific line:

this.FormBorderStyle = FormBorderStyle.None; //<-- if it isn't already!
Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20));

You can change the last two numbers (20, 20) to change how smooth/hard the curve is.