This is a property of many controls. Most of the time, it determines where the Caption or Value of the control appears. Whether Alignment applies to Caption or Value depends on the control. For controls that let you type into them (text box, edit box, combo box, spinner), Alignment is about Values. For other controls (check box, option button, header, label), Alignment is about Captions.
For grid columns, Alignment determines the position of the data shown in the column when the contained control doesn't have focus, and provides a default alignment for the contained control. In this case, it offers a lot more choices than for the other controls.
oObject.Alignment = nAlignment
nAlignment = oObject.Alignment|
Parameter |
Value |
Meaning |
|
nAlignment |
0 |
Left—this is the default for most controls. For columns, this value means "middle left"—flush left and vertically centered. |
|
1 |
Right—this is the default for spinners and for a number of controls in the Middle Eastern version of Windows (in other words, for languages written right-to-left). For columns, this is "middle right"—flush right and vertically centered. |
|
|
2 |
Center—doesn't apply to some controls. For columns, this is "middle center." |
|
|
3 |
Automatic—applies only to text boxes and columns and is their default. It lets them adjust automatically based on whether the Value is character (left-justified) or numeric (right-justified). |
|
|
4 |
Top Left—applies to columns and headers only. |
|
|
5 |
Top Right—applies to columns and headers only. |
|
|
6 |
Top Center—applies to columns and headers only. |
|
|
7 |
Bottom Left—applies to columns and headers only. |
|
|
8 |
Bottom Right—applies to columns and headers only. |
|
|
9 |
Bottom Center—applies to columns and headers only. |
First, be aware that, for those controls where Alignment affects Caption rather than Value (check boxes and the like), the meaning of Alignment is backwards from our instinctive reaction. Alignment here controls the position of the control, not the caption. That is, setting a check box to have left alignment means that the box appears to the left and the caption to the right.
Each option button has its own Alignment property. So, some buttons in a group may be left-aligned while the others are right-aligned. Though we can't imagine why anyone would want to do this, this option is available.
However, changing to right-alignment has another problem. When you right-align option buttons, by default, they're still lined up within the group based on their left edges. That is, the little circles don't line up. To solve the problem, you have to select the individual buttons and use the Layout toolbar or the Format MENU TO align the right edges.
Alignment and AutoSize have a strange relationship. For labels, setting AutoSize to .T. means that the value of Alignment is irrelevant. For check boxes and option buttons, you may want AutoSize set to .T. so that the entire caption shows—actually this isn't particularly related to Alignment, but the problem looks much stranger when using right-alignment than with left.
For grid columns and headers, Alignment has a lot more choices than in the other cases. You can specify not just the horizontal alignment of the item, but its vertical alignment, too. For these controls, Automatic means centered vertically, but with horizontal alignment determined by the data type.
As far as we can tell, Alignment does work properly for headers and labels. That's a start.
oForm = CREATE("Form")
oForm.Show()
oForm.AddObject("MyCheck", "CheckBox")
oForm.MyCheck.Visible = .T.
oForm.MyCheck.AutoSize = .T.
oForm.MyCheck.Caption = "Checker"
oForm.MyCheck.Alignment = 1 && Right
