|
-
May 18th, 2000, 03:57 AM
#1
Thread Starter
New Member
Hi is there a way of adding controls to a form at runtime. Example if you decide you want 2 buttons you can create them in your code, or if you want 20 you can do the same. The only way I have thought of so far is to have 20 buttons on the form and if you only want 2 making the other 18 invisible.
Thanks
-
May 18th, 2000, 05:07 AM
#2
You can create controls using a Control Array. For example, place a CommandButton on a form, with the Index property set to 0. This code will loop through and create 20 command buttons.
Code:
Private Sub Form_Initialize()
For i = 1 To 20
Load Command1(i)
Command1(i).Move 0, 0 + (480 * i)
Command1(i).Visible = True
Next i
End Sub
If you would like to create them from scratch, I know there is a method to do it, but it can only be done in VB6
I do not know the syntax for it either.
-
May 18th, 2000, 05:19 AM
#3
Hold on a sec, I knew I had the syntax for it but I didn't have it on my this computer. I booted up my old P166 computer and found this for you. This method for adding controls is only possible in VB6.
Make a Form with 1 CommandButton on it. Place the following code into it.
Code:
Private Sub Command1_Click()
Controls.Add "VB.CommandButton", "cmdNewButton"
Me!cmdNewButton.Move 0,0
Me!cmdNewButton.Caption = "PRESS"
Me!cmdNewButton.Visible = True
End Sub
I hope this helps you.
[Edited by Megatron on 05-18-2000 at 06:20 PM]
-
May 18th, 2000, 05:25 AM
#4
Thread Starter
New Member
Thankyou
Thankyou as I was in a bind
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|