LC #42 Pipers Alley

View Full Version : dotNetString extent?

10-23-2009, 07:12 PM
So I have a string and I'm painting it into a form in the paint event. How can I test the size of the string that has been painted since I need to take the font and text brush into account?

10-23-2009, 07:30 PM
You can use a .NET TextRenderer to measure your string.

fnt = dotnetobject "System.Drawing.Font" "Courier" 20.0
sz = (dotnetclass "TextRenderer").MeasureText "Measure Me" fnt


10-23-2009, 08:01 PM
Excellent, just posted another question that you might know the answer to Mike. Would you mind having a look?

10-24-2009, 11:25 AM
hi paul, if you are interested in methods for using strings in the paint event you can also look into the stringformat class - it provides paint event alignment and justification methods to arrange strings. I used it recently with an owner drawn tooltip on one of my controls -

10-26-2009, 12:20 PM
Nice Pete, looks just like what I want. So what is the box behind the text? Is that something that you have drawn or is that part of the tool tip?

10-26-2009, 02:30 PM
hi paul, it's just one of the buttons on my hitchhiker control.

CGTalk Moderation
10-26-2009, 02:30 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.