I like John's solution! It's simple, doesn't require messy dll server registration, 
and will definitely work fine on standard browsers that display fonts as specified by 
the font-size style in pixels. And you can pretty much reuse it as an include whenever 
you like. 

The only situation that I know it might fail in, is with Firefox's font zooming cause 
I know Firefox lets you increase/decrease font sizes even with a specified pixel size. 
IE doesn't. 

In any case, I usually avoid having to go to a COM component unless I absolutely HAVE 
to.

-Matias

 

-----Original Message-----
From: Niels Bieze [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, September 29, 2004 10:12 AM
To: [EMAIL PROTECTED]
Subject: RE: [ASP] Calculating the length of a string in pixels

ROFL

Im seriously considering your first option

After a long day of searching, im going with a VB solution,
system.drawing.graphics.measurestring() this will return the width and height on a 
specified string

"give complete solutions, they help others" department:
-On the www this would be pretty moch useless as John stated, because browsers, 
installed fonts etc are different & every browser allows you to fixate your font. but 
im on a intranet :P -as far as I know there is no component that will do this...

Thanks to all! (specially you john, my colleagues are still wondering why I was on the 
floor)


-----Oorspronkelijk bericht-----
Van: John Vieth [mailto:[EMAIL PROTECTED]
Verzonden: woensdag 29 september 2004 15:36
Aan: [EMAIL PROTECTED]
Onderwerp: RE: [ASP] Calculating the length of a string in pixels

Here's a poor man's (or simple man's) solution...

First display in a web page every character (numbers, letters, upper case, lower case, 
etc) that might appear in your app.  Display the characters using the exact same type 
properties, including font family, size, weight, etc.  Make a screen capture of the 
page that displays these characters.  Paste the screen capture into a Photoshop image 
and zoom in on each character so that you can measure its width in pixels.
On paper or a text document, record the width in pixels that corresponds with each 
character.  Once you've gathered all the data, create a VBScript function for your ASP 
pages that computes the width of a string.  The first thing the function must do is 
build a 2-dimensional array to contain all the pairs of data--character and width.  
Then the function should parse through the string one character at a time, look up 
each character in the array to find its width, and add the width to an integer that 
represents the total width of the string.  The function would then return the integer.



------------------------ Yahoo! Groups Sponsor --------------------~-->
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/17folB/TM
--------------------------------------------------------------------~-> 

---------------------------------------------------------------------    
 Home       : http://groups.yahoo.com/group/active-server-pages
---------------------------------------------------------------------
 Post       : [EMAIL PROTECTED]
 Subscribe  : [EMAIL PROTECTED]
 Unsubscribe: [EMAIL PROTECTED]
---------------------------------------------------------------------
Yahoo! Groups Links



 



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/17folB/TM
--------------------------------------------------------------------~-> 

---------------------------------------------------------------------    
 Home       : http://groups.yahoo.com/group/active-server-pages
---------------------------------------------------------------------
 Post       : [EMAIL PROTECTED]
 Subscribe  : [EMAIL PROTECTED]
 Unsubscribe: [EMAIL PROTECTED]
--------------------------------------------------------------------- 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/active-server-pages/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to