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
?
views:
264answers:
4
+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
2010-05-25 19:26:08
+1
A:
SizeF size = myLabel.CreateGraphics().MeasureString(myLabel.Text, myLabel.Font);
Timothy Carter
2010-05-25 20:01:49
A:
Surely the width is the width? Remeber to disbale Autosize
if you want to fix the width at a certain value.
Sir Graystar
2010-05-25 20:11:54