How to calculate the minimum size of _client_ form .net windows?

I am trying to programmatically position certain controls on a form based on the difference between the minimum size of the forms and its client size - this, unfortunately, leads to different results depending on the theme loaded by the user (basically the problem seems to be related to that the title and the shape of the border have different heights / widths in different themes). I tried using the height of the whole window (including the title bar, etc.), but this does not work properly: (

this, unfortunately, leads to the fact that the controls contain a mismatch. in this particular use case, using automatic layout controls (such as a flow layout panel) is not a viable solution.

I need to skip something really obvious - is there a better way to do this?

Sorry if this question sounds silly

Many thanks Dave

+3
source share
3 answers

The only way I was able to figure out for sure is to do something like:

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

and then use it when ever I need to create something, the client has a shape (I used it when I wanted the shape to be automatic for 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;

NTN

Edit: I tried using the SystemInformation.Border3DSizeand properties SystemInformation.BorderSize, but they also did not give the correct width for me.

+5
source

100%, , , , .., , , , CodeProject. .., , pinvokes GetSystemMetrics, , . pinvoke.net - GetSystemMetrics.

, , , .

0

, , , , - :

Dim clientRectDelta As Integer = Me.Height - Me.ClientRectangle.Height - (SystemInformation.Border3DSize.Height * 2)
Dim actualMinimumHeight As Integer = Me.MinimumSize.Height - clientRectDelta
Dim deltaHeight As Integer = Me.ClientRectangle.Height - actualMinimumHeight

However, this ignores any control-dependent heights of the dependent topics (i.e., the height of the column headers when changing lists, which seem to change the overall height of the list, which can cause overlaps, etc.), but it seems to work mostly.

Many thanks to Pondidum, tommieb75 and nobugz who helped with this problem! (sorry, but I don’t have enough reputation to mark all your answers up to +1).

0
source

Source: https://habr.com/ru/post/1724089/


All Articles