N
Nathan Laff
I have a custom label, that as the width changes, the height will change to
fit all the text in the label...
I use to do this like this...
int newHeight = (int)Math.Ceiling(g.MeasureString(this.Text,
this.Font, this.Width - this.Padding.Left,
StringFormat.GenericDefault).Height);
Then override the onPaint and do this...
e.Graphics.DrawString(this.Text, this.Font, new
SolidBrush(this.ForeColor), new
Rectangle(this.Padding.Left,this.Padding.Top,this.Width -
this.Padding.Left,this.Height), StringFormat.GenericDefault);
Works great.
Now I'm trying to move to TextRenderer and can't seem to get it to do either
of these things.
I'm trying to measure like this...
int newHeight = TextRenderer.MeasureText(g, this.Text,
this.Font, this.Size, TextFormatFlags.Bottom).Height;
and draw like this...
TextRenderer.DrawText(e.Graphics, this.Text, this.Font,
this.ClientRectangle, this.ForeColor, this.BackColor,
TextFormatFlags.Default);
The label doesn't resize, and even if I use the resize code from the
Graphics.MeasureString, the TextRender.DrawText doesn't work.
Please help!
fit all the text in the label...
I use to do this like this...
int newHeight = (int)Math.Ceiling(g.MeasureString(this.Text,
this.Font, this.Width - this.Padding.Left,
StringFormat.GenericDefault).Height);
Then override the onPaint and do this...
e.Graphics.DrawString(this.Text, this.Font, new
SolidBrush(this.ForeColor), new
Rectangle(this.Padding.Left,this.Padding.Top,this.Width -
this.Padding.Left,this.Height), StringFormat.GenericDefault);
Works great.
Now I'm trying to move to TextRenderer and can't seem to get it to do either
of these things.
I'm trying to measure like this...
int newHeight = TextRenderer.MeasureText(g, this.Text,
this.Font, this.Size, TextFormatFlags.Bottom).Height;
and draw like this...
TextRenderer.DrawText(e.Graphics, this.Text, this.Font,
this.ClientRectangle, this.ForeColor, this.BackColor,
TextFormatFlags.Default);
The label doesn't resize, and even if I use the resize code from the
Graphics.MeasureString, the TextRender.DrawText doesn't work.
Please help!