I have a Word userform with 60+ controls of varying types. I would like to evaluate the form every time a control_change event is triggered and change the enabled state of the form's submit button. However, I really don't want to write and maintain 60 on change event handlers.
相关问题
- Laravel Option Select - Default Issue
- HTML form is not sending $_POST values
- How to use Control.FromHandle?
- Stop child process when parent process stops
- Fire resize event once not based on timing
相关文章
- What does it means in C# : using -= operator by ev
- System.Runtime.InteropServices.COMException (0x800
- How are custom broadcast events implemented in Jav
- Show a different value from an input that what wil
- Vanilla Web Component custom event attributes and
- How can I detect/watch “dirty-status” of an angula
- Unregister a XLL in Excel (VBA)
- Programming a touch screen application with SWING
You can create an event-sink class that will contain the event-handling code for all of your controls of a particular type.
For example, create the a class called
TextBoxEventHandler
as follows:Now you need to create & hook up an instance of that class for each control of the appropriate type on your form:
Note that the reason you need to add the event handler instances to a collection is simply to ensure that they remain referenced and thus don't get discarded by the garbage collector before you're finished with them.
Clearly this technique can be extended to deal with other types of control. You could either have separate event handler classes for each type, or you could use a single class that has a member variable (and associated property & event handler) for each of the control types you need to handle.
In that case you have few options, because event handlers cannot be shared in VBA/VB6
Option 1: Use a central handling function which is called from every event handler.
Option 2: Organize your controls in control arrays.
Combining both options your total event handler count will shrink considerably and the remaining handlers are just brainless stubs for the one true event handler.