
- •Using UserForms
- •Creating UserForms
- •Adding and Manipulating Controls
- •Setting Properties
- •Types of Controls
- •The Label Control
- •The TextBox Control
- •The ComboBox Control
- •The ListBox Control
- •The CheckBox Control
- •The OptionButton Control
- •The ToggleButton Control
- •The Frame Control
- •The CommandButton Control
- •The TabStrip Control
- •The MultiPage Control
- •The ScrollBar Control
- •The SpinButton Control
- •The Image Control
- •Controls in the Sample Application
- •Naming Controls
- •UserForm Events
- •Your First Event Procedure
- •Useful Events
- •Events in the Sample Application
- •Working with Forms in AutoCAD
- •Launching a Form
- •Filling a ListBox
- •Selecting a Line
- •The Call Stack
- •The Locals Window
- •Finishing Touches
- •Automatically Loading a VBA Project
- •Automatically Running a VBA Procedure
- •Protecting Your VBA Code
- •Importing and Exporting Components

TYPES OF CONTROLS |
9 |
Types of Controls
The Controls toolbox contains 14 controls. In this section, you’ll learn what the various controls are useful for. With these controls, you can build whatever interface your AutoCAD application needs.
In addition to the 14 standard controls, AutoCAD can use custom controls. There are thousands of custom controls available. They do everything from displaying hierarchical information in a tree to managing outgoing faxes. Custom controls are beyond the scope of this chapter, but you can learn more about them by looking up Custom Controls in the VBA Help feature.
The Label Control
The Label control (see Figure 99.5 for some examples of the Label control and the tool that creates it) is meant to hold static text. Although you can programmatically change the text displayed by the label at runtime, the user can never edit the text displayed in a label.
In the Windows interface, labels are generally used for short pieces of explanatory text. For example, if you have a place for the user to choose a line color, you’ll probably place a label with the caption “Line Color” nearby.
Figure 99.5 The Label control
Copyright ©2001 SYBEX, Inc., Alameda, CA |
www.sybex.com |

10 |
CHAPTER NINETY-NINE • USING VBA TO CREATE AUTOCAD APPLICATIONS |
The TextBox Control
The TextBox control allows the user to enter text in a recessed box on a UserForm. Figure 99.6 shows a few text boxes, together with the Controls toolbox icon used to create them. The most important property of the TextBox control is its Text property. You can read the Text property to determine what a user has entered in a text box, or write to it to display your own information to the user in an editable form.
Typical Windows applications use text boxes any time they want to accept freeform input. If you’re creating a line in AutoCAD and want the user to be able to type in the length of the line, a text box is a good choice.
Figure 99.6 The TextBox control
The ComboBox Control
You can use a ComboBox control (Figure 99.7) to allow the user to choose from a fixed list of items in a limited space. The combo box will be familiar to any Windows user. Most of the time it displays a single item, but it includes a “drop-down” arrow that will display a list of choices. Figure 99.7 shows combo boxes in both normal and expanded form.
Combo boxes are appropriate whenever there’s a list of things to choose from, but you don’t need to see the whole list at the same time. A combo box can also (depending on its properties) allow the user to enter a value that’s not contained in the list. In AutoCAD itself, the color control on the toolbar is a modified ComboBox control.
Copyright ©2001 SYBEX, Inc., Alameda, CA |
www.sybex.com |

TYPES OF CONTROLS |
11 |
Figure 99.7 The ComboBox control
The ListBox Control
The ListBox control is very similar to the ComboBox control. The major difference is that the list is visible at all times, as shown in Figure 99.8. List boxes are used whenever the user should be able to choose from a fixed list of values and user interface space is not at a premium. For example, you might use a list box to allow the selection of one of a limited number of drawing primitives to use in the next operations.
Figure 99.8 The ListBox control
Copyright ©2001 SYBEX, Inc., Alameda, CA |
www.sybex.com |

12 |
CHAPTER NINETY-NINE • USING VBA TO CREATE AUTOCAD APPLICATIONS |
The CheckBox Control
The CheckBox control is used to present a binary (True/False, Yes/No, On/Off) choice to the user. Check boxes are either checked or unchecked. You can tell what state a check box is in at any given time by inspecting the Value property of the control. Figure 99.9 shows several check boxes, together with the Controls toolbox icon used to create them.
Check boxes are appropriate any time the user must choose from a set of options that are not mutually exclusive. You can use the Frame control, discussed later in this chapter, to group CheckBox controls together.
Figure 99.9 The CheckBox control
The OptionButton Control
OptionButton controls provide another way to choose between True and False for a value. Figure 99.10 shows several option buttons. The major difference between check boxes and option buttons (other than their appearance) is that only one in a group of option buttons can be true at any given time. This makes option buttons useful for choosing among mutually exclusive options.
For example, if you have an AutoCAD interface that allows users to choose between four fixed line types, you might use a group of option buttons to present the four types. This ensures that only one line type could actually be chosen.
Copyright ©2001 SYBEX, Inc., Alameda, CA |
www.sybex.com |