Resizing a button

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I want to resize a button depending on its label.
I do this:

// In Form1 ctor
Graphics gr=button1.CreateGraphics(); //
button1.Size=gr.MeasureString(button1.Text, button1.Font).ToString();

but the buttin misses the last letter. It wont work even if I round up the
SizeF value returnde from MeasureString. It works only if I use this code:

button1.Size=gr.MeasureString(button1.Text+/*add offset*/"W",
button1.Font).ToString();


Thanks
 
Are you taking the borders into consideration? For a 3D-bordered button you
will need to add (SystemInformation.Border3DSize.Width * 2).
 
Back
Top