|
-
Nov 4th, 2000, 01:12 PM
#1
Thread Starter
Frenzied Member
I need to add events to a new object during runtime. This is what I have so far:
Code:
Dim Form_To_Create As Form
Form_to_Create.Caption = "Test"
Form_To_Create.Show
How would I add code to the Form_Click Event?
Also, how would you put an image over another image?
I tried a picturebox over another but you saw the square of the object over the form, but I would like to be able to see just the image in front. Thanks.
retired member. Thanks for everything 
-
Nov 4th, 2000, 01:36 PM
#2
transcendental analytic
That won't work, to actually create the form you need to use New keyword and a class, in this case form1, which you would have to do in designtime
Code:
Dim Form_To_Create As Form
Set Form_To_Create = New Form1 '<---
Form_To_Create.Caption = "Test"
Form_To_Create.Show
On the other hand this form will be created and can stil be changed during runtime
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 5th, 2000, 08:49 AM
#3
Thread Starter
Frenzied Member
But how can I add code to Form1_Click of the new Form after I create it?
retired member. Thanks for everything 
-
Nov 5th, 2000, 11:08 AM
#4
Use the WithEvents statement.
-
Nov 5th, 2000, 12:16 PM
#5
Thread Starter
Frenzied Member
retired member. Thanks for everything 
-
Nov 5th, 2000, 02:36 PM
#6
This will add an event for a button created at runtime
Code:
Private WithEvents cmd As CommandButton
Private Sub Form_Load()
Set chkBox = Me.Controls.Add("VB.CommandButton", "Btn")
Me!Btn.Move 0, 0
Me!Btn.Caption = "Button1"
Me!Btn.Visible = True
End Sub
Private Sub cmd_Click()
MsgBox "You pressed the button"
End Sub
-
Nov 6th, 2000, 04:27 PM
#7
Thread Starter
Frenzied Member
Please apply this...
How would you have a button, that when clicked, created a button that, when clicked, popped up a MsgBox that said "hello, you have clicked the second Command Button that was created during runtime by another Command button."?
retired member. Thanks for everything 
-
Nov 6th, 2000, 05:34 PM
#8
Add the following to a Form with 1 CommandButton.
Code:
Private WithEvents cmd As CommandButton
Private Sub Command1_Click()
Set cmd = Me.Controls.Add("VB.CommandButton", "Btn")
Me!Btn.Move 0, 0
Me!Btn.Caption = "NewButton"
Me!Btn.Visible = True
End Sub
Private Sub cmd_Click()
MsgBox "hello, you have clicked the second Command Button that was created during runtime by another Command button"
End Sub
-
Nov 6th, 2000, 07:43 PM
#9
Thread Starter
Frenzied Member
last question!
When I do the above it only works to create one. What would I do to create another after another button that say "hello, you have clicked the second Command Button that was created during runtime by another Command button" when you click the original Button? Now, it get an error saying there is already a Btn on the form.
retired member. Thanks for everything 
-
Nov 7th, 2000, 05:28 PM
#10
Thread Starter
Frenzied Member
Also, without arrays. In other words, have the function creat a button and add the name to a list box. You can click the original button again and again, each time adding a Btn1, Btn2 and so forth(remember, no arrays) and when you click the new buttons, they all do the same things (i.e. MsgBox "you clicked me")Anyone?
retired member. Thanks for everything 
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
|