I use code to draw rounded form
this.FormBorderStyle = FormBorderStyle.None;
Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20));
When use maximize function form size stay same
this.WindowState = FormWindowState.Maximized;
What need to change to work maximize function?
Uday DodiyaPosted Jan 11, 2023, 10:55 AM
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: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.