I created this class as an answer to a question asked in the General VB Forum and thought that it could fit here. This class has a TextWidth and a TextHeight property which works the same way as it does for a Form, a PictureBox, or the Printer object. The only difference is that you don't need any Forms or Controls to use it. So if you need to messure the text length (in pixels) from within an ActiveX DLL this is the code to use.
The class expose a Font object property and the TextWidth/Height methods, so it's very easy to use:The Font object is initilized as MS Sans Serif 8pt, which is used if you don't change it.VB Code:
Dim oFont As CTextSize Set oFont = New CTextSize With oFont.Font .Name = "Times New Roman" .Size = 12 .Bold = True End With MsgBox oFont.TextWidth("Hello World!")
EDIT: Corrected a possible memory leak.


Reply With Quote