![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
A designer, on the other hand, provides a visual design window within the Visual Basic development environment. The Visual Basic forms designer is included by default in all versions of the development environment. The Professional and Enterprise editions of Visual Basic provide additional designers. Properties Make The ObjectEvery Visual Basic object has a set of properties that controls how it looks and behaves. This is true even of insertable objects, although their property sets are relatively small, because so much of their behavior is determined by the parent application and not by Visual Basic. Rather than just talking about properties, lets create a simple Visual Basic project that demonstrates how they work. This program will display text in a Text Box, permitting the user to change the size of the Text Box and the color of the text. Starting To Design The InterfaceThis project is designed specifically to illustrate the relationships between objects, properties, and code. It consists of a single dialog box with eight controls. Ill be honest and admit that the program does not do anything useful, but I believe it will be a valuable learning tool. To start, fire up Visual Basic; if it is already running, select New from the File menu. Choose Standard EXE from the New Project dialog box. The first control well place on the form is a Text Box. Using the techniques you learned earlier in this chapter, place a Text Box in the upper left corner of the form. The exact size doesnt matterperhaps two grid units high by eight units wideyou can always adjust it later. There are other controls to be placed, but first lets set the properties for the Text Box that we just added. Changing The Text Property Make sure that the Text Box is selected, then take a look at the Properties window. If this window is not displayed, press F4. The Properties window displays the properties of the selected object, with the objects name (that is, its Name property) displayed in the title bar. Just below the title bar is a box that displays the objects name and its type. This box is like a Visual Basic Combo Box controlyou can click on the arrow at the right end of the box to see a list of all the controls on the current form. Select a control by choosing it from the list, just as if you had clicked on it on the form. The list in the Properties window lists all of the controls properties, either in alphabetical order (on the Alphabetic tab) or organized by category (on the Categorized tab). The property names are in the left column, and the property values in the right column. You use the scroll bar to display different properties, then select a specific property by clicking on it. The area at the bottom of the Properties window displays a brief description of the highlighted property. Scroll until the Text property is visibleon the Categorized tab, it is listed in the Misc section. The default value for this is Text1, as shown in Figure 3.4. The Text property of a Text Box specifies the text that is displayed in the control. We need to change the Text property of this control. Follow these steps:
Notice that the new property is reflected not only in the Properties window, but also in the Text Box control on the form. Suppose you made a typing error while entering the Text property. Do you have to go back and retype the whole thing? Not at all. If you click on the property value in the right column of the Properties window, Visual Basic will display an editing cursor at the end of the text, allowing you to edit the text using the regular editing keys. Here are brief descriptions of each of the keys:
Changing The Font Property Next, well change the Text Boxs Font property. As you can guess, this property determines the font used for the text in the control. Scroll the Properties list to bring the Font property into view and click once on the property name. A small button with three dots displays next to the current font value. Click on the button to display the Font dialog box, which is shown in Figure 3.5. You can also double-click on the Font property name to go directly to the dialog box. Select from the Font, Font Style, and Size lists to specify the font you want, then click on OK. I suggest using a font 12 points in size. The new font is reflected immediately in the Text Box on the form. Depending on the size of the font you selected, you may need to increase the size of the Text Box to display all of the text. Adding The Other ControlsNow that the first control is complete, well add all of the remaining controls and then change their properties as needed. We need three Command Buttons, three Option Buttons, and one Frame. What is the Frame control for? Think back to our discussion of Option Button controls. I mentioned that only one Option Button in a group can be set to on at any time. The obvious question is, How does one define a group of option buttons? By placing them in a Frame, thats how. If you want more than one group of Option Buttons on a form, you need one Frame for each group.
Placing Option Buttons in a Frame requires a specific technique. If you add some Option Buttons to a form, add a Frame, and finally drag the Option Buttons onto the Frame, they will certainly appear to be in the Frame, but Visual Basic will not treat them as a group. To have a set of Option Buttons treated as a group, you have to put the Frame on the form first, then draw the Option Buttons within the Frame. Here are the steps required:
Next, add the three Command Buttons, placing them in the lower right area of the form. At this point, the form will look more or less like Figure 3.6. Before changing the properties of these newly added controls, we should save the project. Select Save Project from the File menu. Because the project and form files have not been given names yet, Visual Basic will prompt you for names. I used Properties Demo for the project and Properties for the form, but you can assign other names if you like.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |