[Closed] dotNetString extent?
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?
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
Excellent, just posted another question that you might know the answer to Mike. Would you mind having a look?
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 –
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?