ElektroStudios
ElektroStudios

Reputation: 20464

Generic function to return String measure (Graphics.MeasureString)

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

Upvotes: 0

Views: 290

Answers (1)

Sriram Sakthivel
Sriram Sakthivel

Reputation: 73442

You can use TextRenderer

return TextRenderer.MeasureText(text , font);

Upvotes: 2

Related Questions