How can you add events to controls added in runtime
using the ADD method?
Printable View
How can you add events to controls added in runtime
using the ADD method?
Code:'add a command button to a form dynamically at run time
Option Explicit
Private WithEvents btnObj As CommandButton
Private Sub btnObj_Click()
MsgBox "This is a dynamically added button."
End Sub
Private Sub Form_Load()
Set btnObj = Controls.Add("VB.CommandButton", "btnObj")
With btnObj
.Visible = True
.Width = 3000
.Caption = "This button was created on the fly!"
.Top = 1000
.Left = 1000
End With
End Sub
Quote:
Originally posted by Rwhite
How can you add events to controls added in runtime
using the ADD method?
Try using the CreateEventProc Method. If this doesn't help, let me know.
johnson_m
Code:If you use the code I pasted the events come with the button. All you have to do is use them..ie>
Private Sub btnObj_Click()
MsgBox "This is a dynamically added button."
End Sub
or any other event belonging to the control created...you just have to choose to use.
How would you make more than one?
Same way as you made the first.