Groups | Blog | Home
all groups > asp.net > august 2007 >

asp.net : [STRING, MeasureString method] problem on retrieving the px length


bruce barker
8/31/2007 12:21:20 PM
as the server does not have access to the the browser fonts, web forms
can not do MeasureString. you would have to do this with client code.


-- bruce (sqlwork.com)

[quoted text, click to view]
teo
8/31/2007 7:57:16 PM
I have to measure the length of a string in a Label,
to set the adequate Label width
(because not all browsers support the auto-size Label property).


I decide to use the 'MeasureString' method.
It works on a Win Form,
but it doesn't work on a Web Form.

I see the usual blue zig-zag underline
under the 'CreateGraphics' method;
the error says that 'CreateGraphics' is not a member of
System.Web.UI.WebControls.Label

Any help?

Here my code:

Imports System.Drawing

Label1.Text = "Hallo"

Dim instance As Graphics = Label1.CreateGraphics()
Dim text As String = Label1.Text
Dim font As New Font("Arial", 10)
Dim returnValue As SizeF
returnValue = instance.MeasureString(text, font)

teo
8/31/2007 10:23:55 PM
[quoted text, click to view]

But I'm telling to the server that the font is "Arial,10" !

Like this:
Dim font As New Font("Arial", 10)


[quoted text, click to view]
AddThis Social Bookmark Button