tags:

views:

125

answers:

2

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;
+6  A: 

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?

Timbo
Thanks. Works.
Corey Trager
Note you might have some unpredictable behavior if you do this with docked or anchored controls, especially when doing a live resize.
rein
+1  A: 

why not use the button's height property?

SnOrfus