All,
I came across some code that doesn't work very well. It adjusts the
size of a button based on the font that we use. The font can be
adjusted by the user.
using (Graphics g = this._btnClose.CreateGraphics())
{
this._btnClose.Height = (int)(g.MeasureString(this._btnClose.Text,
this._btnClose.Font).Height * 1.25);
}
This is not enough, since the text is being cut off at the bottom (up
to 2 pixels). To be honest, a factor of 1.25 seems rather arbitrary
to me. I don't like this code for other reasons... one being that a
value of 25.99 will yield a value of 25.
I figure there is probably a better way. Any suggestions?
Thanks,
Brian
Herfried K. Wagner [MVP] - 29 Jan 2007 19:00 GMT
"Bilz" <BrianGenisio@gmail.com> schrieb:
> I came across some code that doesn't work very well. It adjusts the
> size of a button based on the font that we use. The font can be
[quoted text clipped - 12 lines]
>
> I figure there is probably a better way. Any suggestions?
Well, why not use a larger scaling factor?

Signature
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Bilz - 29 Jan 2007 19:13 GMT
On Jan 29, 2:00 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.at> wrote:
>Well, why not use a larger scaling factor?
>
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
You're kidding, right? Hard coding a "magic value" like that is sure
to fail again down the road again.
Bilz - 29 Jan 2007 19:02 GMT
> All,
>
[quoted text clipped - 16 lines]
> Thanks,
> Brian
Ok, I figured it out. Instead of that funky math, I just set AutoSize
to true, and AutoSizeMode to GrowAndShrink. This took care of it for
me.
Thanks,
B