Click to See Complete Forum and Search --> : Adding Controls
Rani
Nov 8th, 1999, 09:42 PM
Can someone please help me adding more than 10 command buttons to my form at runtime.
Aaron Young
Nov 8th, 1999, 09:51 PM
Create a Command Button at Design Time, set the Index Property to Zero then at Runtime..
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
aarony@redwingsoftware.com
adyoung@win.bright.net
devarajulu
Nov 8th, 1999, 09:58 PM
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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.