Generic function to return String measure (Graphics.MeasureString)

274 Views Asked by At

In C# or VB.NET how I could write a generic function which only should need to pass a string and a font to return the measure of the font?

This is What I've tried:

Private Function Get_Text_Measure(ByVal text As String, _
                                  ByVal font As Font) As SizeF

    Using g As Graphics = ...
        Return g.MeasureString(text, font)
    End Using

End Function
1

There are 1 best solutions below

4
On BEST ANSWER

You can use TextRenderer

return TextRenderer.MeasureText(text , font);