Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
teo - 31 Aug 2007 18:57 GMT
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)
bruce barker - 31 Aug 2007 20:21 GMT
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)

> I have to measure the length of a string in a Label,
> to set the adequate Label width
[quoted text clipped - 24 lines]
>
>                 Debug.Print(returnValue.Width.ToString)
teo - 31 Aug 2007 21:23 GMT
>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)

>-- bruce (sqlwork.com)
>
[quoted text clipped - 26 lines]
>>
>>                 Debug.Print(returnValue.Width.ToString)

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.