Notifications
Clear all

[Closed] dotNetString extent?

 PEN

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?

5 Replies

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

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

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

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?

hi paul, it’s just one of the buttons on my hitchhiker control.