[RESOLVED] How do you add Events to a DYNAMICALLY created UC OBJ ?
Hello,
I've got my UserControl, but I'm creating/referencing it on the FLY @ Runtime.
Is there a way for it to support EVENTS without turning it in to a CLASS etc ?
Re: How do you add Events to a DYNAMICALLY created UC OBJ ?
Look up the VBControlExtender in the manual.
Quote:
The VBControlExtender object is primarily used when dynamically adding a control to the Controls collection using the Add method. The VBControlExtender object is particularly useful for this purpose because it provides a generic set of properties, events, and methods to the developer. Another feature of the object is the ObjectEvent event which is designed to parse any event raised by a dynamically added control. The example below declares an object variable as VBControlExtender, and sets the variable when adding a control. The example also shows how you can program the ObjectEvent event.
Re: How do you add Events to a DYNAMICALLY created UC OBJ ?
Re: [RESOLVED] How do you add Events to a DYNAMICALLY created UC OBJ ?
A link should not be required.
Every legal copy of VB6 comes with the necessary documentation CDs. If you do not have these CDs your copy of VB6 is not legal. It's right in the EULA.
Re: [RESOLVED] How do you add Events to a DYNAMICALLY created UC OBJ ?
I've got a legal copy of VB6 but I don't have the documentation CD's any more as I lost them. Does that mean that my copy of VB6 is no longer legal? ;)
Re: [RESOLVED] How do you add Events to a DYNAMICALLY created UC OBJ ?
Quote:
Originally Posted by
dilettante
A link should not be required.
Every legal copy of VB6 comes with the necessary documentation CDs. If you do not have these CDs your copy of VB6 is not legal. It's right in the EULA.
However, sometimes the install of the MSDN library stuffs up and after a while VS6.0 may fail to realize you actually have the help installed alone with Visual Studios.
Re: [RESOLVED] How do you add Events to a DYNAMICALLY created UC OBJ ?
What the EULA mentions only covers "transfer rights" when you sell or give away Visual Studio 6.0 or individual separate products like VB6.
Re: [RESOLVED] How do you add Events to a DYNAMICALLY created UC OBJ ?
Code:
Option Explicit
' Declare object variable as CommandButton and handle the events.'
Private WithEvents cmdObject As CommandButton
Private Sub Form_Load()
'Add button control and keep a reference in the WithEvents variable'
Set cmdObject = Form1.Controls.Add("VB.CommandButton", "cmdOne")
cmdObject.Visible = True
cmdObject.Caption = "Dynamic CommandButton"
End Sub
'Handle the events of the dynamically-added control'
Private Sub cmdObject_Click()
Print "This is a dynamically added control"
End Sub