PDA

View Full Version : dotNetString extent?


PEN
10-23-2009, 08: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?

biddle
10-23-2009, 08: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
sz.ToString()

.biddle

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

http://forums.cgsociety.org/showthread.php?f=98&t=818819

LoneRobot
10-24-2009, 12:25 PM
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 -

PEN
10-26-2009, 01: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?

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

CGTalk Moderation
10-26-2009, 03: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.