Sometimes, we have to calculate a label's width dynamically , depending on the provided text. In order to do that, use the following,
float width = Graphics.FromImage(new Bitmap(1, 1)).MeasureString("Hello world!", new Font("Verdana", 14)).Width
You will have to mention the font family and the desired size.
Monday, June 15, 2009
Subscribe to:
Post Comments (Atom)
Thanks!
ReplyDeleteIt's the shortest solution ;)