Results 1 to 3 of 3

Thread: Adding Controls

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 1999
    Posts
    6

    Post

    Can someone please help me adding more than 10 command buttons to my form at runtime.

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Create a Command Button at Design Time, set the Index Property to Zero then at Runtime..
    Code:
    Private Sub Form_Load()
        Dim I As Integer
        For I = 0 To 9
            If I Then Load Command1(I)
            With Command1(I)
                .Move 0, I * Command1(0).Height
                .Caption = "Command" & (I + 1)
                .Visible = True
            End With
        Next
    End Sub
    
    Private Sub Command1_Click(Index As Integer)
        MsgBox "You Pressed " & Command1(Index).Caption
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  3. #3
    Junior Member
    Join Date
    Feb 1999
    Location
    Bangalore, Karnataka, India
    Posts
    16

    Post

    1. paste a command button on the form. in the properties window set the index property to 0. this will make the control the first element of a control array which u can load at run time. lets assume the control name as cmdDynamic
    2. at run time have the following code in whichever event you want the controls to be loaded (i am assuming Form Load event here)
    private sub Form_Load()
    for Counter = 1 to NoOfComponents - 1
    load cmdDynamic(Counter)
    cmdDynamic(Counter).Left = cmdDynamic(Counter - 1).Left
    cmdDynamic(Counter).Top = cmdDynamic(Counter - 1).Top + cmdDynamic(Counter - 1).Height
    next Counter
    end sub

    Hope this helps
    Dev

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