*Experts* Bucky Posted July 23, 2002 *Experts* Posted July 23, 2002 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) :) Quote "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* Thinker Posted July 23, 2002 *Gurus* Posted July 23, 2002 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. Quote Posting Guidelines
*Gurus* divil Posted July 23, 2002 *Gurus* Posted July 23, 2002 Use the Graphics.MeasureString method Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Gurus* Thinker Posted July 23, 2002 *Gurus* Posted July 23, 2002 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) Quote Posting Guidelines
*Gurus* divil Posted July 23, 2002 *Gurus* Posted July 23, 2002 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. Quote 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* Bucky Posted July 23, 2002 Author *Experts* Posted July 23, 2002 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. :) Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.