On Jan 29, 1:33 pm, "Bilz" <BrianGeni...@gmail.com> wrote:
> 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
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
|