Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

What need to change to work maximize function?

What I have tried:

this.WindowState = FormWindowState.Maximized;
Posted
Updated 11-Jan-23 1:15am
v2

Width and Height are ignored if the Region property has been set - it overrides them.
So when you maximize it, the system changes the Width and Height, but still uses the preset Region for display. (It can't alter that, it has no idea what else you are doing with it.)

Set the Region back to null when you maximize, and back to the size you want when you restore.

Do note however, that you don't get rounded corners on a Maximized form: it occupies the whole monitor surface.
 
Share this answer
 
Comments
BillWoodruff 11-Jan-23 7:19am    
having gone through the complexity of doing this in WinForms and finding it took lots of effort to make it "look right" whatever the user did ... i wonder if, for a beginner (?), maybe a suggestion to go with WPF is appropriate.
OriginalGriff 11-Jan-23 7:33am    
Heck of a learning curve for a beginner ... and the last time I looked the editor was still, um, a bit "amateur hour" compared with the WinForms one?
BillWoodruff 11-Jan-23 7:51am    
i wanted the goodies in WPF, but bounced off XAML. when Sinofsky killed SilverLight, and took MS into the "Metro" weirdness ... and, then WPF cycled through deprecated and ? ... i lost interest.

the work Pete 0'Hanlon and others at CP in the "Disciples" group was fascinating, and, technically daunting.
If you want rounded corners on a maximized Form, or when a user drags the Form size handle, you must implement handlers for one or more of the various events raised that are triggered by any change in Form size, or WindowState.

In your handler(s) you can use the WindowState property to tell you if the Form is Minimized, Maximized, Normal.

Look at the ResizeBegin, ReSize, ReSizeEnd, SizeChanged. Events.

To do this right, you need to have special functions that reset the current Region, and calculate the new Region based on current Form state. You should DoubleBuffer the Form.

This is not trivial code, but, you can find examples online with minimum effort.

We're not going to write code for you: you get started, and come back with code and specific questions.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900