Placing two labels exactly after eachother

C

Christer Bermar

Hello,

I was wondering how to oder two labels in a ASP.NET web form exactly after
eachother by settings its LEFT and WIDTH propertys. Depending on the font
used and length of the string, this is dynamic. Is there an exact way to
calculate how many pixels a label is?

Regards,
Christer Bermar
 
C

Christer Bermar

Yes i understand that it is the width property, but it is what to put there
that is what im looking for. If a user inputs "label1" in the left label
with a font "Arial" it will be x pixels long. This is what i want to
calculate so i can position the right label after the left label.

How does one calculate the number of pixels a string/label consumes? If i
can get the number of pixels a label is long, i can just position the other
label with label.Width=Unit.Pixel(x);

Regards,
Christer Bermar
 
C

Cor Ligthert

Christer,

Untested to get the lenght of the string text of the time now
\\\
Dim textSize As SizeF =
Graphics.FromHwnd(Me.Handle).MeasureString(Now.ToString, Me.Font)
///
I hope this helps?

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