Reputation: 565
How can I set my labels to align on the right even when they have diffrent lenghts.
I have a set of labels which are occuring next to each other and also underneath each other.
The problem now is that they always align from the left within the label row,but I need them to align on the right as they are showing sums from other rows.
Just to verify I am not talking about the text align I am looking for a solution to align my labels.
Thanks in advance
Upvotes: 15
Views: 37214
Reputation: 11
My method is even more strange. I create the labels and then when laying out the fields for the report adjust the labels for number (etc) that are to be right aligned Note: all labels end with 'lbl' - txtNew is the report column text box. - get the column's left edge plus the width of the column minus the width of the label. Works! Just not my favorite way to do it.
' *** NEED TO CALC POSITION FOR RIGHT JUSTIFY OF LABEL !!!!!
If ShouldRightJustify(rs.Fields(i).Type) Then
rpt.Section(acPageHeader).Controls(rs.Fields(i).Name & "lbl").Left = _
(lblCol + txtNew.Width) _
- rpt.Section(acPageHeader).Controls(rs.Fields(i).Name & "lbl").Width
End If
Upvotes: 1
Reputation: 27342
You should be able to do it at runtime using the following code:
'find the current right alignment position
Dim rightAlign As Integer = Label1.Left + Label1.Width
'set the text (assumes AutoSize is set to True)
Label1.Text = value
'adjust position so the right hand point is in the same position as before
Label1.Left = rightAlign - Label1.Width
Upvotes: 7
Reputation: 17001
If you are asking how to do this from the designer, use the Format Menu. Select all the controls you want to align, then click the control you want the other aligned to. Do Format > Align > Rights.
If you are trying to do this at run-time you can loop through the controls you want to align and set their .X property according to their width. For example. To align a label so that it's right side is at X=200... SomeLabel.X = 200 - SomeLabel.Width.
Upvotes: 0
Reputation: 942368
Simply set the AutoSize property to False in the designer. Adjust the size to fit the column. Then set the TextAlign to one of the right-alignment ones.
Upvotes: 37