Results 1 to 2 of 2

Thread: Adding controls via user control property page

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2008
    Posts
    21

    Adding controls via user control property page

    Good afternoon, im not sure if this is in the right place but im sorry if its not, what i have is a user control that i have made, and im now in the process of designing the property pages, but im having difficulty with a certain part.

    What i want to do is when the user access the Property page, and inserts text into the into a text box and clicks a button, the user control will add the label there and then, for example, with the Microsft Windows Common Controls toolbar control, when you click Insert Button, its adds it automatically, or the Status Bar control, it adds it all dynamically.

    I have written in functions were it does it at runtime, but it means putting all manor of code within the Form_Load() of each form were the control is present. i shall show my runtime AddItem code below
    Code:
    Public Sub AddItem(strLabelTitle As String, strFormName As String, _
                        Optional Picture As IPictureDisp)
        
        '//Store The Information
        '//In A Private Type Created Earlier (.FormTitle & .LabelTitle Are Collections)
        With LinkList
            .FormTitle.Add strFormName
            .LabelTitle.Add strTitle
        End With
        
        '//Get the amount of items already in the list
        Dim cnt As Integer
        cnt = LinkList.FormTitle.Count
    
        '//Work Out Height of User Control
        '//Labels and Images Are Stacked Underneath Each other
        '//This Sets the Control height
        If cnt = 1 Then
            Height = topImage.Height + 510
        Else
            Height = topImage.Height + lblCall(0).Top + CInt(cnt * 330) + 60
        End If
    
        '//Load New Versions Of The Image And Label
        '//Label & Image Sit side by side in the user control
        Load imgCall(cnt)
        Load lblCall(cnt)
    
        '//Set Image Properties (imgCall(0)  is the one we are duplicating)
        With imgCall(cnt)
            If cnt = 1 Then
                .Top = 120
            Else
                .Top = CInt(CInt(330 * CInt(cnt - 1)) + 120)
            End If
            .Picture = Picture
            .Visible = True
            .Width = 240
            .Height = 240
            .Left = 240
        End With
    
        '//Set Label Properties (lblCall(0) Is The One Were Duplicating)
        With lblCall(cnt)
            .Caption = Chr(32) & strTitle
            .Visible = True
            .Left = 480
            '//Work Out Top Value
            If cnt = 1 Then
                .Top = 120
            Else
                .Top = CInt(CInt(330 * CInt(cnt - 1)) + 120)
            End If
        End With
    End Sub
    Can the above code be adapted in anyway so that we can add the label & images at design time. I have searched high and low on this, ive even tried to look at other toolbar source code trying to decipher this, but just cant seem to make any head way. At the moment my Form_Load() on my main form is up to 260 lines, due to adding all the information on form load.

    Any Help would be most appreciated
    Thank you & Kind Regards
    Devon

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Feb 2008
    Posts
    21

    Re: Adding controls via user control property page

    Just bumping this up, does nobody know how to do it? ive practially searched the internet but cannot find a way.

    Kind Regards
    Devon

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