It seems that this property is only updated correctly when the object is visible. Or rather, when its .Visible property is .T.
You can keep it hidden, by postponing form upgrades, with the .LockScreen property.
Here are the results of a quick test:
with ThisForm.Label1
ThisForm.LockScreen = .T.
.Caption = "This is a very long caption"
.Visible = .T.
MyWidth = .Width
wait window "Width: " + trans(MyWidth)
.Visible = .F.
ThisForm.LockScreen = .F.
endwith
Tested in Visual FoxPro 6. Despite the delay introduced throughthe "wait window", nothing is shown on the form, because of the .LockScreen.
HTH,
Hilmar.
>Hi guys,
>
>Is it possible to get the width of a label control before displaying it on the form?
>
>I created a class that is composed of a Label and a Textbox controls, they are contained within a container control. The caption of the Textbox is dynamically assign based on a parameter I pass. Upon assigning the caption of the label control, I tried to get its width property so that I can reassign the left property of the textbox so that they will not overlap.
>
>The problem is, even if the label was already assigned to have the proper caption, the width property is not being change. The label is already set to autosize and still the width is always set to 40 even if I assign a long caption for it.
>
>Any Idea?
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)