|
|
Title | Create a new ActiveX button using Controls.Add and respond all of its events |
Description | This example shows how to create a new ActiveX button using Controls.Add and respond all of its events in Visual Basic 6. The program makes a VBControlExtender for the control and catches its ObjectEvent event. |
Keywords | button, Controls.Add, event |
Categories | Controls, Tips and Tricks |
|
|
Thanks to James Hansen.
The program declares a VBControlExtender with the WithEvents keyword. It creates a new command button and saves the result in this variable. Note that this control must be an ActiveX control so the program uses the Forms.CommandButton.1 control class.
Later the program catches the VBControlExtender's ObjectEvent event to see what the control is doing.
|
|
Private WithEvents VirtualObj As VBControlExtender
Private Sub Form_Load()
Dim ClassName As String
Dim ObjName As String
ClassName = "Forms.CommandButton.1"
ObjName = "VirutalCommand1"
Set VirtualObj = Controls.Add(ClassName, ObjName, Me)
With VirtualObj
.Left = 100
.Top = 100
.Visible = True
.Object.Caption = ObjName
End With
End Sub
Private Sub VirtualObj_ObjectEvent(Info As EventInfo)
Debug.Print Info.Name; Info.EventParameters.Count
If Info.Name = "Click" Then Beep
End Sub
|
|
|
|
|
|