measure string 
Author Message
 measure string

Does anyone know how to get the correct size of a string?
I've tried MeasureString, and it doesn't seem to be
accurate. I've noticed others have had the same issue, but
I never found a workaround.

thanks,
todd



Sun, 02 Oct 2005 02:33:57 GMT  
 measure string
Hello Todd,


Quote:
> Does anyone know how to get the correct size of a string?
> I've tried MeasureString, and it doesn't seem to be
> accurate. I've noticed others have had the same issue, but
> I never found a workaround.

Have a look at the value of MeasureString's stringFormat parameter.

Regards,
Herfried K. Wagner



Sun, 02 Oct 2005 05:05:28 GMT  
 measure string
i looked at it, but i'm not really sure what i'm looking
for. do you have a complete example?

Quote:
>-----Original Message-----
>Hello Todd,


>> Does anyone know how to get the correct size of a
string?
>> I've tried MeasureString, and it doesn't seem to be
>> accurate. I've noticed others have had the same issue,
but
>> I never found a workaround.

>Have a look at the value of MeasureString's stringFormat
parameter.

>Regards,
>Herfried K. Wagner

>.



Sun, 02 Oct 2005 05:58:53 GMT  
 measure string
Can you show some code, I am not clear on what you mean by correct size and
accurate. Are you using a fixed with font?


Quote:
> Does anyone know how to get the correct size of a string?
> I've tried MeasureString, and it doesn't seem to be
> accurate. I've noticed others have had the same issue, but
> I never found a workaround.

> thanks,
> todd



Sun, 02 Oct 2005 06:01:46 GMT  
 measure string
I found this code in another newsgroup. So, I'm not sure
if I'm using it correctly. To test it, I just filled up a
text box, label, etc., where i decided the size. However,
the resulting calculation was off.

dim g as Graphics
g = me.CreateGraphics

Dim sf as New StringFormate
(StringFormat.GenericTypographic)

Dim sz as SizeF = g.MeasureString("Some text", Me.Font, 0,
sf)

return sz.Width

Quote:
>-----Original Message-----
>Can you show some code, I am not clear on what you mean
by correct size and
>accurate. Are you using a fixed with font?



>> Does anyone know how to get the correct size of a
string?
>> I've tried MeasureString, and it doesn't seem to be
>> accurate. I've noticed others have had the same issue,
but
>> I never found a workaround.

>> thanks,
>> todd

>.



Sun, 02 Oct 2005 06:19:08 GMT  
 measure string
Todd,

I still don't understand what your using GDI+ for the size for?

Please explain what your indication of not accurate is ('abc' returns a
different size than 'ijk') ?

Quote:
> >> Does anyone know how to get the correct size of a string?

Do you mean the length as in how many characters are in the string?

Vince


Quote:
> I found this code in another newsgroup. So, I'm not sure
> if I'm using it correctly. To test it, I just filled up a
> text box, label, etc., where i decided the size. However,
> the resulting calculation was off.

> dim g as Graphics
> g = me.CreateGraphics

> Dim sf as New StringFormate
> (StringFormat.GenericTypographic)

> Dim sz as SizeF = g.MeasureString("Some text", Me.Font, 0,
> sf)

> return sz.Width

> >-----Original Message-----
> >Can you show some code, I am not clear on what you mean
> by correct size and
> >accurate. Are you using a fixed with font?



> >> Does anyone know how to get the correct size of a
> string?
> >> I've tried MeasureString, and it doesn't seem to be
> >> accurate. I've noticed others have had the same issue,
> but
> >> I never found a workaround.

> >> thanks,
> >> todd

> >.



Sun, 02 Oct 2005 12:01:53 GMT  
 measure string
Do you mean the pixel-width of the string? Or the actual number of
characters inside it?

' Number of characters:
Dim intLength As Integer
Dim strMyString As String = "Hello"

intLength = Len(strMyString)
MsgBox(intLength)

Displays: 5

--
==============================================
Happy to Help,
Tom Spink

http://dotnetx.betasafe.com > .NET code (soon)

One Day,

Quote:
> Does anyone know how to get the correct size of a string?
> I've tried MeasureString, and it doesn't seem to be
> accurate. I've noticed others have had the same issue, but
> I never found a workaround.

> thanks,
> todd



Sun, 02 Oct 2005 16:52:10 GMT  
 measure string
Todd,
    The default StringFormat used for MeasureString includes 'padding'
around the whole string which is why you want to use
StringFormat.GenericTypographic.  Even this can be off by a pixel or so at
times.  See past discussions in microsoft.public.dotnet.framework.drawing on
this subject.  Note that if you need to measure trailing spaces you will
have to create your own StringFormat object and set the appropriate
StringFormatFlags item on it.  Also you have to draw with the same
StringFormat used for measuring if you are using this for placement
purposes.

Ron Allen

Quote:
> I found this code in another newsgroup. So, I'm not sure
> if I'm using it correctly. To test it, I just filled up a
> text box, label, etc., where i decided the size. However,
> the resulting calculation was off.

> dim g as Graphics
> g = me.CreateGraphics

> Dim sf as New StringFormate
> (StringFormat.GenericTypographic)

> Dim sz as SizeF = g.MeasureString("Some text", Me.Font, 0,
> sf)

> return sz.Width

> >-----Original Message-----
> >Can you show some code, I am not clear on what you mean
> by correct size and
> >accurate. Are you using a fixed with font?



> >> Does anyone know how to get the correct size of a
> string?
> >> I've tried MeasureString, and it doesn't seem to be
> >> accurate. I've noticed others have had the same issue,
> but
> >> I never found a workaround.

> >> thanks,
> >> todd

> >.



Sun, 02 Oct 2005 21:55:41 GMT  
 measure string
pixel width

Quote:
>-----Original Message-----
>Do you mean the pixel-width of the string? Or the actual
number of
>characters inside it?

>' Number of characters:
>Dim intLength As Integer
>Dim strMyString As String = "Hello"

>intLength = Len(strMyString)
>MsgBox(intLength)

>Displays: 5

>--
>==============================================
>Happy to Help,
>Tom Spink

>http://dotnetx.betasafe.com > .NET code (soon)

>One Day,


>> Does anyone know how to get the correct size of a
string?
>> I've tried MeasureString, and it doesn't seem to be
>> accurate. I've noticed others have had the same issue,
but
>> I never found a workaround.

>> thanks,
>> todd

>.



Sun, 02 Oct 2005 22:02:16 GMT  
 measure string
In which case, just do the following:

Dim strText = "The String Being Measured"
Dim g As Graphics = Me.CreateGraphics
Dim sfSize As SizeF = g.MeasureString(strText, Me.Font)

MsgBox("Width: " & sfSize.Width & vbCrLf & "Height: " & sfSize.Height)

--
==============================================
Happy to Help,
Tom Spink

http://dotnetx.betasafe.com > .NET code (soon)

One Day,

Quote:
> pixel width

> >-----Original Message-----
> >Do you mean the pixel-width of the string? Or the actual
> number of
> >characters inside it?

> >' Number of characters:
> >Dim intLength As Integer
> >Dim strMyString As String = "Hello"

> >intLength = Len(strMyString)
> >MsgBox(intLength)

> >Displays: 5

> >--
> >==============================================
> >Happy to Help,
> >Tom Spink

> >http://dotnetx.betasafe.com > .NET code (soon)

> >One Day,


> >> Does anyone know how to get the correct size of a
> string?
> >> I've tried MeasureString, and it doesn't seem to be
> >> accurate. I've noticed others have had the same issue,
> but
> >> I never found a workaround.

> >> thanks,
> >> todd

> >.



Sun, 02 Oct 2005 23:45:01 GMT  
 measure string
I started with that. When I test it, it's not accurate.

Here's why:
http://www.codeproject.com/cs/media/measurestring.asp

This article contains 2 workarounds. The first one seems
to work, but the second gives the same result using your
technique. So, I'll probably use the first one. Anyways,
thanks for the help.

todd

Quote:
>-----Original Message-----
>In which case, just do the following:

>Dim strText = "The String Being Measured"
>Dim g As Graphics = Me.CreateGraphics
>Dim sfSize As SizeF = g.MeasureString(strText, Me.Font)

>MsgBox("Width: " & sfSize.Width & vbCrLf & "Height: " &
sfSize.Height)

>--
>==============================================
>Happy to Help,
>Tom Spink

>http://dotnetx.betasafe.com > .NET code (soon)

>One Day,


>> pixel width

>> >-----Original Message-----
>> >Do you mean the pixel-width of the string? Or the
actual
>> number of
>> >characters inside it?

>> >' Number of characters:
>> >Dim intLength As Integer
>> >Dim strMyString As String = "Hello"

>> >intLength = Len(strMyString)
>> >MsgBox(intLength)

>> >Displays: 5

>> >--
>> >==============================================
>> >Happy to Help,
>> >Tom Spink

>> >http://dotnetx.betasafe.com > .NET code (soon)

>> >One Day,


>> >> Does anyone know how to get the correct size of a
>> string?
>> >> I've tried MeasureString, and it doesn't seem to be
>> >> accurate. I've noticed others have had the same
issue,
>> but
>> >> I never found a workaround.

>> >> thanks,
>> >> todd

>> >.

>.



Mon, 03 Oct 2005 00:54:56 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Measuring the 'width' of a string

2. How to Measure the Success of Purging

3. VBA for lookup unit of measure

4. performance measuring - help

5. Measuring height of table

6. Measure Text

7. Printer Unit of Measure

8. how to measure speed connection

9. measure items

10. I need to measure how long a code run, in seconds

11. Measuring Viewtime on a website

12. can millisecs be measured?

 

 
Powered by phpBB® Forum Software