[STRING, MeasureString method] problem on retrieving the px length

  • Thread starter Thread starter teo
  • Start date Start date
T

teo

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)

Debug.Print(returnValue.Width.ToString)
 
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)
 
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.

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

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