PDA

Click to See Complete Forum and Search --> : Just messing with Labels


Mindcrime
Jun 3rd, 2001, 01:23 PM
I have put 4 Label controls onto my usercontrol. Label1 holds the value 'Record', Label2 holds a value passed to the control, Label3 holds the value 'of' and Label4 holds the total records count.

Label2 & label4 are set to Autosize, the Label_Change event adjusts the length of the entire usercontrol with spaces.

Everyting works just chipper!

How do I change the usercontrols.left property on the form that it is active on?
I want the control to be right justified.

Thanks Guys

bascy
Jun 14th, 2001, 06:18 AM
You cant change the .Left and .Top property of a control from within, you can only do that from the parent / container it is defined in.

So you have to define an event in the usercontrol EventControlResized, and RAISE this event after you change the sizes of the labels. The total width of the labels can be passed as a parameter to the event.

In the form that uses the usercontrol, you can catch the event with a Sub UserControl_EventControlResized(intLabelWidth as integer) and change the size of the control according to the width of the labels


'----------------Usercontrol------------------

Public Event EventLabelsResized(intTotalWidth as integer)

Private Sub label1_Change()
'Code for placing the labels on the right place within the
'usercontrol

Raise EventLabelsResized(label1.width + label2.width + _
label3.width + label4.width)
End Sub

--------------------FORM--------------------------

Private sub uctControl_EventLabelsResized(intWidth as integer)
uctControl.Left = uctControl.left + uctControl.width - intWidth
End Sub



Hope this helps
Bascy