- by x32x01 ||
Want to give your Windows Forms app a modern and stylish look?
One simple tweak can make your form stand out - rounded corners!
In this guide, you’ll learn how to create smooth, rounded edges for any C# WinForms window using the GDI32 API.
Rounded corners make your app look cleaner and more polished - similar to modern Windows 11 apps. 
Instead of using the default rectangular edges, you can easily customize your form’s region with just a few lines of code.
Here’s the complete C# code to create a borderless form with rounded corners 
Let’s break down what’s happening step by step:
The
Here,
This function creates a region in the shape of a rounded rectangle.
You provide:
This removes the default rectangular window frame so your custom rounded region can take over.
Finally,
assigns the new region to your form, making it display with smooth rounded edges 
You can change the last two parameters in
Higher numbers → more rounded corners
Lower numbers → subtle curve
If you’re removing borders, your window can look flat.
To fix that, add a drop shadow effect using the Windows API or form painting methods for a sleek floating look
That’s it! With a few lines of code, you can give your old-school WinForms UI a modern refresh. Rounded corners make your C# applications look more elegant, especially when combined with custom colors or gradient backgrounds 
Now you’re one step closer to building professional-looking desktop apps with C# and .NET!
In this guide, you’ll learn how to create smooth, rounded edges for any C# WinForms window using the GDI32 API.
Why Add Rounded Corners?
Rounded corners make your app look cleaner and more polished - similar to modern Windows 11 apps. Instead of using the default rectangular edges, you can easily customize your form’s region with just a few lines of code.
Full C# Code Example
Here’s the complete C# code to create a borderless form with rounded corners C#:
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
[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, // width of ellipse
int nHeightEllipse // height of ellipse
);
public Form1()
{
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.None;
Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20));
}
}
}
Code Explanation
Let’s break down what’s happening step by step:
Importing the Windows API
The [DllImport] attribute lets you use functions from native DLLs.Here,
CreateRoundRectRgn is imported from Gdi32.dll, part of the Windows GDI (Graphics Device Interface).
Defining the Function
This function creates a region in the shape of a rounded rectangle.You provide:
- Form dimensions (
Width,Height) - Corner radius (
20,20in this example)
Removing Default Borders
this.FormBorderStyle = FormBorderStyle.None;This removes the default rectangular window frame so your custom rounded region can take over.
Applying the Rounded Region
Finally, C#:
Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(...));
Customize the Corner Radius
You can change the last two parameters in CreateRoundRectRgn to adjust the curve: C#:
Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 40, 40)); Lower numbers → subtle curve
Pro Tip: Add a Drop Shadow
If you’re removing borders, your window can look flat.To fix that, add a drop shadow effect using the Windows API or form painting methods for a sleek floating look
Wrap-Up
That’s it! With a few lines of code, you can give your old-school WinForms UI a modern refresh. Rounded corners make your C# applications look more elegant, especially when combined with custom colors or gradient backgrounds Now you’re one step closer to building professional-looking desktop apps with C# and .NET!
Last edited: