Create label with varied length run-time.

  • Thread starter Thread starter Tracey
  • Start date Start date
T

Tracey

My application requires to create labels with varied
length at runtime. But I don't know how to do that.

However, the font of string displayed in label is
different, how can I decide the length of the actual
width of the label ?

Thanks!
 
Hello,

Tracey said:
My application requires to create labels with varied
length at runtime. But I don't know how to do that.

However, the font of string displayed in label is
different, how can I decide the length of the actual
width of the label ?

You may want to set the label's AutoSize property to True. You can use
Graphics.MeasureString for getting the height/width of a string.

HTH,
Herfried K. Wagner
 
Hello,

Tracey said:
Can you write a small example for me?

\\\
Dim gr As Graphics = Me.Label1.CreateGraphics()
Dim s As Size = gr.MeasureString("Hello World!", Me.Label1.Font).ToSize()
gr.Dispose()
///

HTH,
Herfried K. Wagner
 
Back
Top