Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted

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 can't do so if I don't know the width of the text.

 

If there's 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 Domino's pizza, I know) :)

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

  • *Gurus*
Posted

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.

  • *Gurus*
Posted

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 don't

exist anymore. (See Graphics Changes in Visual Basic .NET)

  • *Gurus*
Posted
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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

  • *Experts*
Posted

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 don't know the size to beign with!? *sigh*

 

/me kicks MSDN

 

Anyway, thanx a lot Divil, that's perfect. :)

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...