Rick Becker
asked on
How do I add an Event Handler at run time in VB6
Greetings,
The question title says it all. I am adding Controls to a form dynamically (at run time) and I need a way to add an Event Handler to the Control as well.
I know that in VB.NET there is a AddHandler function but that function does not seem to exist for VB6 or at least I can't seem to locate it.
BTW, I am Not creating an array of Controls so the 'Events' are not available (exposed) through that mechanism.
Thanks for any help you can give
rrbecker
The question title says it all. I am adding Controls to a form dynamically (at run time) and I need a way to add an Event Handler to the Control as well.
I know that in VB.NET there is a AddHandler function but that function does not seem to exist for VB6 or at least I can't seem to locate it.
BTW, I am Not creating an array of Controls so the 'Events' are not available (exposed) through that mechanism.
Thanks for any help you can give
rrbecker
Basically you can't. VB6 uses control arrays to accomplish this. The WithEvents keyword only allows you to handle ONE control. It is possibly to create a dynamic control and assign it to a variable declared using WithEvents but you can only create ONE dynamic control in this way. You must have a declaration for each "dynamic" control which makes it pretty silly and you might as use a control array since you must plan ahead at design time.
ASKER
Hi Idle_Mind
Ok, how about this. I have a structure that contains a Command Button (SSCommand).
I create an array of these structures and eventually add the Command Button to a Form.
How do I, (or can I) get at the 'Button_Click()' event for each command button in the structure?
-------example structure----------------- -
Type ItemDataStructure
ItemIndex As Integer
ItemNumber As Integer
'ItemName As String
ItemGroupName As String
ItemButton As SSCommand <<-- Infragistics command button
ButtonName As String
ParentName As String
ButtonWidth As Integer
ButtonHeight As Integer
ButtonTop As Integer
ButtonLeft As Integer
ButtonOrder As Integer
End Type
-------------------------- ---------- ---------- --
Any Ideas?
BTW, I need to step out for a while, be back later today
rrbecker
Ok, how about this. I have a structure that contains a Command Button (SSCommand).
I create an array of these structures and eventually add the Command Button to a Form.
How do I, (or can I) get at the 'Button_Click()' event for each command button in the structure?
-------example structure-----------------
Type ItemDataStructure
ItemIndex As Integer
ItemNumber As Integer
'ItemName As String
ItemGroupName As String
ItemButton As SSCommand <<-- Infragistics command button
ButtonName As String
ParentName As String
ButtonWidth As Integer
ButtonHeight As Integer
ButtonTop As Integer
ButtonLeft As Integer
ButtonOrder As Integer
End Type
--------------------------
Any Ideas?
BTW, I need to step out for a while, be back later today
rrbecker
If the control supports it then you would need to create a control array of SSCommand. When you create a new structure, also load another button into the control array. Then instead of storing a button reference in your structure, you store the INDEX of the button in the control array.
ASKER
Hi Idle_Mind,
I'm back.... I've found that I can create and add the SSCommand button to a form or panel by using the following syntax:
------------snippet------- ---------- ---
MainStruct.GroupStructure( GroupCount er).ItemSt ructure(It emCounter) .ItemButto n.Containe r = MainStruct.GroupStructure( GroupCount er).GroupI temPanel
-------------------------- ---------- -
and this would display a new SSCommand button on my form. I can set all the other properties including Height, Width, Top and Left but I guess I still have the problem of being able to 'Read' the 'Click' event of the button.
If you have any other ideas I would appreciate it, otherwise I'll revert back to a 'Control' array and close this ticket.
Thanks in advance
rrbecker
I'm back.... I've found that I can create and add the SSCommand button to a form or panel by using the following syntax:
------------snippet-------
MainStruct.GroupStructure(
--------------------------
and this would display a new SSCommand button on my form. I can set all the other properties including Height, Width, Top and Left but I guess I still have the problem of being able to 'Read' the 'Click' event of the button.
If you have any other ideas I would appreciate it, otherwise I'll revert back to a 'Control' array and close this ticket.
Thanks in advance
rrbecker
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Idle_Mind,
Not the answer I was 'Hoping' for but the 'Correct' answer none-the-less. You have helped me with problems in the past and have always given me the 'Best' solution possible.
So again, thanks for all your help, I will proceed to implement the 'Control Array'.
rrbecker
Not the answer I was 'Hoping' for but the 'Correct' answer none-the-less. You have helped me with problems in the past and have always given me the 'Best' solution possible.
So again, thanks for all your help, I will proceed to implement the 'Control Array'.
rrbecker
Dim WithEvents newControl As New Text1
then using Text1's events?
J.