|
-
Jul 27th, 2000, 06:48 PM
#1
Thread Starter
New Member
How do I make it so when you click on a button, it will add another button, plus I have a textbox so you can add whatever script you want it , so how would you make it so they click on a button, and it will make another button with whatever caption they choose and which ever script they want it such as MsgBox or somethin...i know how to do all that but dont know how to make the new button, and for it to stay when u open the prog. next time
-
Jul 27th, 2000, 07:26 PM
#2
To add a button dynamically:
Code:
Private Sub Command1_Click()
Controls.Add "VB.CommandButton", "Button1"
Me!Button1.Move 0, 0
Me!Button1.Caption = Text1
Me!Button1.Visible = True
End Sub
But in this case, it's probably best to load them out of a Control Array. You make them stay on the App by saving them to the Registry when they are created, then simply loading them when the App is loaded again.
Make a Form with a 2 CommandButton's and a TextBox. Call 1 of the CommandButton's Buttons and set it's index property to 0.
Code:
Private Sub Command1_Click()
iCount = Buttons.Count
Load Buttons(iCount)
Buttons(iCount).Move 0, 0
Buttons(iCount).Caption = Text1.Text
Buttons(iCount).Visible = True
SaveSetting "MyApp", "MySection", "ButtonCount", iCount
SaveSetting "MyApp", "Button", iCount, Text1.Text
End Sub
Private Sub Form_Load()
iCount = GetSetting("MyApp", "MySection", "ButtonCount")
Print iCount
For i = 1 To iCount
MsgBox (i)
Load Buttons(i)
Buttons(i).Move 0, 0
Buttons(i).Caption = GetSetting("MyApp", "Button", i)
Buttons(i).Visible = True
Next i
End Sub
[Edited by Megatron on 07-27-2000 at 08:30 PM]
-
Jul 27th, 2000, 10:05 PM
#3
Thread Starter
New Member
yea...but still missin one part
That works great, but that only changes the caption...I have another text box for the buttons script part...so if someone types MsgBox "blah", it will make the button with the caption they typed, and put that command in the button, so when they open the prog again their buttin will be their so they can click it and it bring up that message box
-
Jul 28th, 2000, 01:13 AM
#4
Well ....
stoluos,
Looks like we have to wait for VB 8 or something for that. VB6 allows you to dynamically add controls, but you cannot dynamically add the events for the controls, at least to the best of my knowledge. If ever you find a solution to your problem, I am always interested to know.
See you....
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
|