I would think an algorithm would not be a straight forward answer. Here is
why I would think so:
Width, when using pixels(px) is a fixed length: at 1pt = 1/72 inch, 200px
would aprox 2.78 inches. The Size attribute is the number of characters
(i.e. size=50 means 50 characters wide) so it is dependent on your font type
and size. And unless you use a fixed font size, as client inceases/decreases
browser font the text box, using size attribute, will grow/shrink
accordingly...and client can still override that. Further complicating that
is that font "size" really is applicable to the height of the font, not the
width. The width is "proportional" and only relative to the height.
Based on that it's easiest to set size = number of characters you allow as
input or at least the number you will show (the rest will ticker tape).
You can just set it directly in the html code for the page. Example:
<asp:textbox id="Textbox1" runat="server" Width="200px"
Size="28"></asp:textbox>
This assumes 10 pt Verdana font, you could fit aprox 28 characters into a
200px textbox, so Size=28
In code you could do the same. Example:
Textbox1.Attributes.Add("Size","28)
Here are some measurements equivalents. But again, for a font they really
only apply to the height.
in: inches -- 1 inch is equal to 2.54 centimeters.
pt: points -- the points used by CSS2 are equal to 1/72th of an inch.
pc: picas -- 1 pica is equal to 12 points.
px: pixels -- typical 96 or 72 pixels per inch (ppi)
Perhaps you could use the bitmap and graphics objects in the framework to
derive this. I know you can use them to measure a string of a given font
and size and get the pixels.
"Elmo Watson" <sp*****@nospam.yahoo.com> wrote in message
news:uX**************@TK2MSFTNGP14.phx.gbl...
In HTML - for a textbox (input), I would use the 'Size' Attribute
In an ASP.Net TextBox - I use 'Width' - - (like 200px)
However, for other browsers - Other than IE - the size attribute isn't
added - - I can add it, but in able to get the sizes correct, I need some
corresponding algorithm for Width vs Size - -
Does anyone know how the Size attribute is attained?
Let's say I wanted to add a Size attribute to a textbox in page_Load - - I
wanted the size to equal the 200px width I use - -
How does that equate?