Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
George Omura. Lisp programing tutorial for AutoCAD customization / Using VBA to Create AutoCAD Applications - Omura, George.pdf
Скачиваний:
116
Добавлен:
02.05.2014
Размер:
883.43 Кб
Скачать

ADDING AND MANIPULATING CONTROLS

5

Figure 99.1 A new UserForm

If you don’t see the Controls toolbox when you create a UserForm, select View Toolbox from the VBA IDE menus.

Adding and Manipulating Controls

To add a control to a UserForm, first click the desired control in the Controls toolbox and then click the UserForm. For example, on your UserForm, you need a label control to display some static text. Figure 99.2 shows how the screen looks after clicking the Label tool (the capital A icon) in the Controls toolbox and then clicking the UserForm.

Adding a control by clicking the UserForm creates a control of the default size. You can create a control of any size by dragging a box with the control’s cursor on the UserForm.

Copyright ©2001 SYBEX, Inc., Alameda, CA

www.sybex.com

6

CHAPTER NINETY-NINE • USING VBA TO CREATE AUTOCAD APPLICATIONS

Figure 99.2 Adding a control to a UserForm

It’s unlikely that you’ll manage to place all controls exactly where you want them on the first try. Fortunately, moving and resizing controls on a UserForm is simple. To move a control to a new location, click the control to select it. This makes the control “active” and displays a set of white boxes on the control’s border, the resizing handles. Once the control is selected, click and hold your cursor anywhere in the interior of the control, and use the mouse to drag it to a new location. A ghost outline of the control will show you the final location when you release the cursor. Figure 99.3 shows how your UserForm looks when you’re dragging controls.

Copyright ©2001 SYBEX, Inc., Alameda, CA

www.sybex.com

ADDING AND MANIPULATING CONTROLS

7

Figure 99.3 Moving a control with the mouse

Resizing controls is just as simple as moving them. To resize a control, select it, and then use the mouse to click and drag any of the resizing handles. The control is resized in the direction that you drag the handle, and a ghost outline on the UserForm shows you the new size that the control will have when you release the mouse button.

You’ll find many ways to modify control size and position on the Format menu. For example, you can select a group of controls and make them all the same size using this menu.

Setting Properties

The default look of a label is pretty dull: It says Label1, and that’s it. Since labels are for static text that you define, you need some way to change the appearance of the label. That’s what the Properties window is for. If the Properties window isn’t visible on your screen, you can display it by choosing View Properties Window.

If you’d like to work with any of the windows in the Visual Basic Editor, you can undock a window by simply double-clicking the window’s caption.

You’re already familiar with the properties of abstract objects such as AutoCAD lines and viewports. Controls are also objects; in fact, one way to think of a control is as an object with a visible interface. To change the appearance or behavior of a control, you modify its properties in the Properties window.

Copyright ©2001 SYBEX, Inc., Alameda, CA

www.sybex.com

8

CHAPTER NINETY-NINE • USING VBA TO CREATE AUTOCAD APPLICATIONS

Figure 99.4 shows the process of modifying the Caption property of the label control you’ve created. The Caption property holds the text that appears in the label control when the UserForm is displayed. To modify a property, take the following steps:

1.Make sure the Properties window is displayed.

2.Make sure the UserForm is showing in the main design window (you can select it from the Window menu if necessary).

3.Select the control name in the combo box at the top of the Properties window.

4.Select the property you wish to change.

5.Enter a new value for the property.

There are several ways to change properties. Some properties, like the Caption property, accept free-form text. Other properties, such as the BorderStyle property, have a fixed list of choices. You can select a choice from the drop-down list, or doubleclick the property to advance it to the next available value. Color properties have a special drop-down list that lets you pick a color on screen. Finally, some properties, such as the label’s Picture property, refer to files, and you can click in the property value to get a Browse button that allows you to choose any file for this property.

Figure 99.4 Changing the Caption property of the Label control

Copyright ©2001 SYBEX, Inc., Alameda, CA

www.sybex.com