Attention: Webforms setting the with of a textbox, depending of the len of the string and the font

T

ton

How can I in VB.NET set the width of a label or textbox depending on the
length of the string and/or the font size.
In my control I'm showing a textbox in a tablecell, which is added to a
table row
after monitoring several textboxes takes two or even three lines, this is
not what i want.

So how can help me out

Ton
 
C

Cor

Hallo Ton,

Have a look at the graphics.measurestring method for that.

I hope this helps?

Cor
 
C

Cor

Hi Ton,

Did you try this.
\\\
Dim g As Graphics = Graphics.FromImage(New Bitmap(1, 1))
Dim stringSize As New SizeF(g.MeasureString _
("Mystringlength", New Font("Arial", 16)))
Dim mysize As Single = stringSize.Width
///

I also never used in this way, and therefore I do not know if the bitmap
size is big enough and the value you get is in pixels, but that you can in
my opinion recalculate to px or whatever you want.

I hope it helps, I was also curious if it did work on a webform because the
webform is not bitmap.

Cor
 

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

Top