In VB6 there was a function for the WindowsForm called TextWidth. This function when called passing a string you would return the width of the string as it will be displayed on your screen. With this I was able to appropriately set the controls width property with the contents of its text property. Making the text to be displayed in its entirety without being cutoff.

Is there a VB.NET equivalent? I looked around for this function and it no longer exists. Is there a system class that would do the same for me

Thanks...

Re: TextWidth by AlexS

AlexS
Tue May 11 19:33:48 CDT 2004

Hi, Angel

you need to check up Graphics.MeasureString method.

HTH
Alex

"Angel" <anonymous@discussions.microsoft.com> wrote in message
news:7D044649-DDE3-456E-8755-EEA36C0CB694@microsoft.com...
> In VB6 there was a function for the WindowsForm called TextWidth. This
function when called passing a string you would return the width of the
string as it will be displayed on your screen. With this I was able to
appropriately set the controls width property with the contents of its text
property. Making the text to be displayed in its entirety without being
cutoff.
>
> Is there a VB.NET equivalent? I looked around for this function and it no
longer exists. Is there a system class that would do the same for me.
>
> Thanks...



Re: TextWidth by Morten

Morten
Wed May 12 03:29:54 CDT 2004

Hi Angel,

As Alex says, Graphics.MeasureString will work in most cases, but it doe=
s =

not return the exact size. It adds a little bit of extra space around it=
, =

so it will return at least the size of the string, given the font and =

graphics object.

To get the exact measurements, you need to use =

Graphics.MeasureCharacterRanges

Happy coding!
Morten Wennevik [C# MVP]