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

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)
 
B

bruce barker

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)
 
T

teo

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top