Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleCreate a new ActiveX button using Controls.Add and respond all of its events
DescriptionThis 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.
Keywordsbutton, Controls.Add, event
CategoriesControls, 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
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated