1

Konu: Placing a variable-width label on a form

Hello:

In the Init in a form, I have the following:

Visual Fox Pro
WITH THISFORM

 
    .lblDewd.Caption = TRIM(ctype)
 
    .lblDewd.left = .left + .width/2 - .lblDewd.width/2
 
ENDWITH

I am placing the text in field ctype in the caption of a label, and then, I try to center the label on the form. However, it does not work, and I do not understand why. The formula is correct; it works for labels with fixed width.

Any suggestions?

Regards,

Hans L

2

Re: Placing a variable-width label on a form

Hans,
An easier way would be to make the label as wide as the form itself and then set the alignment to center.

3

Re: Placing a variable-width label on a form

That is, of course, a possibility, but I also want to change the background color of the label, and that will be seen across the form.

My thought late last night was that perhaps my code was read before the form was fully created, that is, that the form's width was not "known" by the time I used in the code. Could that be the case? I wonder if there is any place to put code when the form's width surely is known.

Regards,

Hans L

4

Re: Placing a variable-width label on a form

With autosize = .t. I do similar processing in form.init and the only thing I do to get actual size is, to turn visibility to true. ie:

Visual Fox Pro
this.myLabel.visible = .t.

so it applies the autosizing and I can read its width now.

5

Re: Placing a variable-width label on a form

Okidoke! I'll try it. Sure it will work.

Hans L