views:

264

answers:

4

I create Label in runtime: Label myLabel = new Label {Text = "somText"};. After that myLabel.Width equals default value 104. How I can know real width of myLabel?

+1  A: 

Did you try myLabel.ActualWidth ?

Ben Hoffstein
+1  A: 

The real width is 104. Labels have a property called AutoSize. The width will expand or contract depending on the text you set. You can set the AutoSize property to false and set your own width though.

icemanind
+1  A: 
SizeF size = myLabel.CreateGraphics().MeasureString(myLabel.Text, myLabel.Font);
Timothy Carter
A: 

Surely the width is the width? Remeber to disbale Autosize if you want to fix the width at a certain value.

Sir Graystar