Results 1 to 2 of 2

Thread: Just messing with Labels

  1. #1

    Thread Starter
    Fanatic Member Mindcrime's Avatar
    Join Date
    Jun 2001
    Location
    Peterborough, UK
    Posts
    555

    Just messing with Labels

    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
    Mindcrime : )
    ICQ 24003332

    VB 5.0, VB 6.0 SP5, COM, DCOM, VB.NET Beta 2, Oracle 8

  2. #2
    bascy
    Guest
    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

    Code:
    '----------------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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width