Page 429 - Microsoft Office Excel 2003 Programming Inside Out
P. 429

Part 5:  Manipulating Excel Objects
                                                      Creating User Forms

                             Table 19-2. Key Properties, Methods, and Events of the UserForm Controls
                             Property/Method      Description
                             Visible	             Property: when True, means that the control is displayed on the   Chapter 19
                                                  form.
                             Width                Property: contains the width of the control in points.
                             ZOrder (zPosition)	  Method: moves the control to the front (fmTop) or the bottom
                                                  (fmBottom) of the z-order.

                             The Height, Width, Top, and Left properties dictate the physical size and placement of the
                             control on the form. The Enabled property determines if the control can receive the focus,
                             whereas the Visible control determines whether the control will be drawn. When the Locked
                             property is True, the user can manipulate the contents of the control but will be unable to
                             change its value. For instance, setting the Locked property to True means that the user could
                             scroll through a large, multi-line text box to see all of the data. If the Enabled property were
                             set to False, the text box control would still be visible, but the user would be unable to scroll
                             to see any text that isn’t currently visible on screen.
                             When two controls overlap, the ZOrder method controls which one is completely visible and
                             which one is partially or totally hidden. Moving a control to the top of the z-order means that
                             it will be displayed last—thus ensuring that the control will be visible even if it overlaps any
                             other controls. Likewise, using ZOrder to move a control to the bottom means that it will be
                             rendered first, and any other control that is rendered later might hide this control from view.

                             TabIndex identifies the order in which the focus will shift from one control to the next when
                             the user presses the Tab key, and TabStop determines whether the control will accept the focus
                             or the focus should shift to the control with the next higher TabIndex value. The Enter and
                             Exit events are fired as the focus shifts from one control to the next on the form. The Exit
                             routine contains a single argument called Cancel, which you can set to True to prevent the
                             user from switching to a different control.

                             Tip  Checking Information
                             Because the code in the Exit event is only executed when the user switches to another con€
                             trol, it’s an excellent time to examine the contents of the control to determine if the value
                             is correct. For example, you can verify that the contents of the control are numeric, and if
                             the user entered an invalid value, you can notify the user using a message box and then set
                             the Cancel argument to True, thus preventing the user from switching to a new control on
                             the same form.

                             The exact meaning of the Value property depends on the control, but in general it contains
                             the value associated with the control. When this value changes, the Change event is fired.
                             Remember that the Value property is different from the Caption property in that the Caption
                             property usually represents a block of text that can be changed only by the program, whereas
                             the Value property usually contains information that can be changed by the user interacting
                             with the form.


                                                                                                       403
   424   425   426   427   428   429   430   431   432   433   434