Corey Trager
Corey Trager

Reputation: 23123

Why does this code to resize the height a .NET Form make the form too small?

My intent is that the form be sized large enough to show the entire "buttonOK", but not much larger. What actually happens is that the resized form ends up to small to even show the button at all.

public MyFormDlg()   
{
    InitializeComponent();
    this.Height = this.buttonOK.Bounds.Bottom + SomePadding;

Upvotes: 3

Views: 227

Answers (2)

Steven Evers
Steven Evers

Reputation: 17186

why not use the button's height property?

Upvotes: 1

Timbo
Timbo

Reputation: 28050

The Height property includes the height of the Window's Title bar, thus the client area (the one the button bounds are relative to) is smaller than you expect.

This works:

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

I didn't find a ClientHeight property, can this be done any simpler?

Upvotes: 6

Related Questions