Width of string w/specific Font object

Bucky

Well-known member
Joined
Dec 23, 2001
Messages
791
Location
East Coast
User Rank
*Expert*
How can I get the width, in pixels, of a string of a certain Font object?

I want to be able to DrawText directly outside the left-hand side of a form, but I cant do so if I dont know the width of the text.

If theres no solution, I guess I can have an invisible, AutoSizing label, set its font and Text properties, then find the Width property. (cheesier than a Dominos pizza, I know) :)
 
With VB6, it would be a simple matter of using the Form.TextWidth
but they did away with that in .net. If you are using the
Graphics.Drawstring method, there are overloaded versions that
have a RectangleF parameter. I think you could use that to set
the area where your text is drawn.
 
This is so frustrating. That looks like a great replacement for the
TextWidth, but MSDN.net makes no mention of it in the areas
talking about what methods to use to replace ones that dont
exist anymore. (See Graphics Changes in Visual Basic .NET)
 
Yes, tell me about it. They provide a helpful statement saying everything to do with graphics has changed, but no further detail. Actually, taking a good look at the methods and properties of the Graphics class pretty much explains it all.
 
I did a Google on this first, and I found this page, but it says use RectangleF. But how can I use the rectangle if I dont know the size to beign with!? *sigh*

/me kicks MSDN

Anyway, thanx a lot Divil, thats perfect. :)
 
Back
Top