Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how does one calculate the minimum _client_ size of a .net windows form?

I am trying to programmatically position certain controls within a form, based on the difference between the forms minimum size and its client size - this unfortunately produces different results depending on what theme the user has loaded (mostly the problem seems to be due to the fact that the title bar and form border have different heights/widths in different themes). I have tried using the height of the entire window (including the title bar etc) but this doesn't seem to work as expected :(

this unfortunately causes contained controls to misalign. in this particular usage scenario, use of automatic layout controls (such as the flow layout panel) isn't a viable solution.

I must be missing something really obvious - is there a better way of doing this?

Apologies if this question sounds dumb

Many Thanks Dave

like image 549
fusi Avatar asked Dec 06 '25 18:12

fusi


1 Answers

The only way i have found of accurately working it out is to do something like:

int delta = this.Height - this.ClientRectangle.Height;

and then use that when ever i need to base something off the client are of the form (I used it when i wanted a form to auto size to some buttons and have an equal border around them).

So for you:

int delta = this.Height - this.ClientRectangle.Height;
int actualMinHeight = this.MinimumSize.Height - delta;

HTH

Edit: I did try using the SystemInformation.Border3DSize and SystemInformation.BorderSize properties but they also did not give the correct widths for me.

like image 141
Pondidum Avatar answered Dec 08 '25 14:12

Pondidum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!