Number of lines of text in Label

Michel,

No, I’m not confused but I admit that my words were terribly wrong.
Graphics are not deprecated, what it’s deprecated it’s drawing directly on them.
Sorry.

So this suggests that these are class, not instance, properties and functions? That’s very interesting. I’ve always used something like Dave’s code and Norman’s suggestion of creating a picture for purposes of calculating string width and height. Is this behavior designed, or just an interesting thing that might go away?

I started by creating a picture then forgot to put it on one of the lines and noticed it did not generate an error. That’s how I discovered that. Yes, it is of interest to know if it is by design. Otherwise, better get back to a good old Dim :wink:

In the action event of a button, the code is executing in the context of the window (SELF = the window), so self.Graphics refers to .Graphics. If there is no ambiguity, you can drop SELF, so Graphics in this context will always be self.Graphics or .Graphics.

However, accessing the Graphics property of the window this way is deprecated, so you should dim a picture object and use it’s Graphics property instead.

Ah, yes; of course. Thanks for pointing that out, Tim.

Sub Action() dim My as New Picture(Label1.Width,Label1.Height) My.Graphics.TextFont = Label1.TextFont My.Graphics.TextSize = Label1.TextSize msgbox str(Floor(My.Graphics.StringHeight( Label1.Text, Label1.width)/My.Graphics.StringHeight("N",20))) End Sub