Learn the most popular programming language of the most popular Operating System: Windows


Adding a Control to a Form and Setting its Properties

With the preceding brief overview of several different types of controls fresh in your mind, consider the procedure for placing a control on a form, and once positioned, changing the properties of a control.  As a rule, the properties of a control should be  set before event procedures (that is, coded procedures)  are written.  This practice enables you to prototype your design before you begin the code-writing process.  A prototype in this instance is a partial, but not full, representation of your finished design.

Adding a Control to a Form

There is a long procedure and a short procedure for adding a control to a form, and each method has merit.  The following is the long procedure:

  1. Select the control you want from the toolbox.
  2. Make the form active by clicking it to indicate where you want to place the control.
  3. Drag the handles on the control to size it the way you want.

The short procedure is simply the following two steps:

  1. In the toolbox, double-click the control you want.  This places the control on the active form.
  2. Move and change the size of the control as needed.

Figure 3.2 shows how you move a control.  Click the center of the control, and drag the control to a new position.  To change the size of the control, click one of the handles (the small black boxes), and drag the control in a horizontal, vertical, or diagonal direction.

Figure 3.2 To size a control, use the square handles on the sides. To move a control, click the center of it and drag it with the mouse.

When placing option buttons within a frame on a form, the longer procedure binds the control to the frame container. (You are asked to use a frame in next section "Learning to Think Visually.")

Setting Properties for a Control

After adding a control to a form, the properties of the control can be modified.  Control properties work in the same way as form properties:  They can be used to change the appearance or the behavior of the control.  Figure 3.3 shows the Properties dialog box for a command button.  Like a form, you can set a wide variety of options for a command.

Besides Caption and Name,command button properties include ways of changing the appearance of the text on the button, the size of the button, and even how you want the cursor to appear when it is placed over the button (the MousePointer property).  You cannot change the color of the button, as the next exercise demonstrates.

Figure 3.3 The properties box for a command button contains a Caption and a Name property and a host of other properties.

Exercise 3.1 Examining the Control Property Box

In this short exercise, you add a command button to a form and change its properties.

  1. Open a new project.
  2. Double-click the Command Button control.  If you place the wrong one on the form, select Edit, Delete to remove the control from the form.
  3. With the Command1 button on the screen (see Figure 3.3), move it to the left-hand side of the form.
  4. Change the BackColor property using the BackColor palette to change the color.
  5. Run the program. What does the BackColor setting change?
  6. Click the form and the Command button. Can you determine why nothing happens? Because you have not indicated what action (that is, what event) is to take place when the button is clicked, the piece missing is a procedure.
  7. Exit to return to the form.
Technorati Tags: ,,

No comments:

Post a Comment


Popular Posts

Search This Blog

Powered by Blogger.

Featured Post

Coded Statements and Methods

In the preceding procedure , you wrote several coded instructions, which introduced two different programming statements and a method: the D...

Recent Posts