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