I use code to draw rounded form
C#
this.FormBorderStyle = FormBorderStyle.None;
Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20));
When use maximize function form size stay same
C#
this.WindowState = FormWindowState.Maximized;
What need to change to work maximize function?

Uday DodiyaRank #239 · 10.3K reputationPosted Jan 11, 2023, 5:55 AM EST
The problem you're experiencing is that when you set the
WindowStateproperty toFormWindowState.Maximized, theWidthandHeightproperties of the form are set to the size of the monitor, which can cause the rounded region to be different from what you expect.One way to fix this issue is to handle the
Resizeevent of the form and re-create the rounded region with the new size of the form. Here's an example:private void Form1_Resize(object sender, EventArgs e) { if (WindowState == FormWindowState.Maximized) { // Get the size of the taskbar int taskbarHeight = Screen.PrimaryScreen.Bounds.Height - Screen.PrimaryScreen.WorkingArea.Height; // Create a new rounded region with the size of the form and the taskbar height Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height - taskbarHeight, 20, 20)); } else { // Create a new rounded region with the size of the form Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20)); } }This code snippet handle event when form is maximized and then set region of form by reducing height by taskbar height.
You should also make sure that you set the
Regionproperty of the form in the constructor of the form as well so that it will take effect immediately when the form is first shown.