Why does this .NET form height code make the form too small?

My intention is for the shape to be large enough to show the entire buttonOK button, but not much more. What actually happens is that the size of the resized shape ends up small to even show the button at all.

public MyFormDlg()   
{
    InitializeComponent();
    this.Height = this.buttonOK.Bounds.Bottom + SomePadding;
+3
source share
2 answers

The property Heightincludes the height of the title bar of the window, so the client area (the one limited by the buttons) is smaller than you expect.

It works:

this.ClientSize = new Size(this.ClientSize.Width,
                           this.buttonOK.Bounds.Bottom + SomePadding);

I did not find the property ClientHeight, can this be done easier?

+6
source

?

+1

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


All Articles