Having determined the ProgID for your intrinsic control, you can declare a
variable of the desired control type, as in the examples of Listing 4.9:
LISTING 4.9
DECLARATIONS OF OBJECT VARIABLES FOR INTRINSIC VB CONTROLS THAT WILL BE ADDED
TO THE CONTROLS COLLECTION AT RUNTIME
Option Explicit
Private WithEvents cmdMyButton As CommandButton
Private WithEvents txtMyTB As TextBox
Private WithEvents lblMyLabel As Label
NOTE :- Limitations on the Use of WithEvents
You can only use the WithEvents keyword in the
General Declarations sections of designer-type
objects, such as forms, UserControls, and Active
Documents. If you try to use WithEvents in the
General Declarations of a Standard (.bas) Module
or in a local variable declaration within any
kind of procedure, you'll receive a compiler
error.
Notice that the three examples all use the WithEvents keyword.
This means that you'll be able to find the declared objects in a code window's
drop-down list and that each object will further provide its event procedures
in the rightside drop-down of the code window for you to program, as illustrated
in Figure 4.16

FIGURE 4.16 Once you've declared your
control using WithEvents, you can see the control
and its events in the drop-down lists of the
Code window.
You can then write your own event-handling code in the event procedures.
Adding and Deleting Controls Dynamically Using the Controls Collection
Topics
Related Topics
See Also
<< Previous | Contents
| Next >>