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

Ad

Opening the Properties Window and Changing Form Properties

Besides a Project Explorer window, each form (or control) contains a Properties window.  As stated in Running a Visual Basic Program, a property is a named attribute of an object.  Properties are used to change the appearance or behavior of objects.

Figure 2.6 illustrates the default Properties dialog box for a form.  If this box is not visible, you can bring it into view by pressing the F4 function key, or choosing View, Properties Window.  With the form having the focus, press your right mouse button and drag down the Properties list.

Figure 2.6  
The Properties dialog box of a form contains the built-in form attributes that you can change.

Over 50 properties can be set for a form.  Although this number seems overwhelming at first, some properties are used so frequently that they represent an initial set to remember.

Form Properties

Caption

Name

BorderStyle

MinButton

MaxButton

ControlBox

WindowSize

BackColor

FontName

FontSize

FontBold

FontItalic

FontStrikethru

FontUnderline

ForeColor

StartUpPosition

To simplify this list somewhat, the items can be grouped by their uses:

  • Seven properties deal with the way in which the form or text appears on the display screen (Caption, BorderStyle, MinButton, MaxButton, ControlBox, WindowSize and StartUpPosition).
  • The identification of an object is specified by the Name property.
  • Font settings are controlled using the Fonts dialog box (FontName, FontSize, FontBold, FontItalic and FontStrikethru).
  • Color settings (ForeColor and BackColor) use a special palette.

There are three ways to change most property settings:

  • Click the property to highlight it, and enter (type in text) the new property setting in the text box.
  • Double-click the setting to view the alternative settings.
  • Click the down arrow to open the drop-down menu for property settings.

Properties for fonts and color launch a separate dialog box for you to enter settings.

Changing a Caption

The Caption property enables you to change the title that appears on the top of a form.  Instead of Form1, use the Caption property to add a title.  To change the caption, select Caption in the Properties dialog box and type the new title in the text box next to the property name.

Changing a Form Name

The Name property specifies the name of the form to be used in writing Visual Basic code. Remember the following rule: The name, not the caption, is the identifier.  When writing coded instructions, the Name property appears as the object name.  To change the name, select Name in the Properties dialog box and type the new name.

Changing the Border Style

The BorderStyle property enables you to change the appearance of the form’s border.  To change the border setting, double-click the current setting to reveal other choices, or click the down arrow to open the drop-down list of the six options.

If you are uncertain about the six border choices and their precise effects, click BorderStyle to give it the focus in the Properties dialog box, and press F1 (the Help function key).  Visual Basic Help displays the six style choices and explains their effects, as shown in Table 2.2.

Table 2.2 The Settings for the BorderStyle Property
Setting Style Description
0 None No border or border-related elements.
1 Fixed Single Can include Control menu icon, title bar, Maximize button, and Minimize button.  Resizable only using Maximize and Minimize buttons.
2 Sizable The default.  The size can be changed using any of the optional border elements listed for setting 1.
3 Fixed Dialog Can include Control menu icon and title bar; can’t include Maxiimize or Minimize buttons.  Not resizable.
4 FixedToolWindow Under 16-bit versions of Windows and Windows NT 3.51 and earlier, behaves like Fixed Single.  Does not display Maximize or Minimize buttons.  Not resizable.  Under Windows 95, displays the Close button and displays the title bar text in a reduced font size.  The form does not appear in the Windows 95 taskbar.
5 SizableToolWindow Under 16-bit version of Windows and Windows NT 3.5 and earlier, behaves like sizable.  Docs not display Maximize or Minimize buttons, Resizable.  Under Windows 95, displays the Close button and displays the title bar text in a reduced font size.  The form does not appear in the Windows 95 taskbar.

The online Help is one of Visual Basic’s strongest features.  Remember, the F1 key is your friend!  Use it often.  The language is just too vast to remember all of it.

Share:

The concept of Focus

The concept of focus is important in Visual Basic.  The object that is selected (such as a form, control, or menu bar selection) is said to have focus.  In order for Visual Basic to know what file to save, it is necessary to click the object to give it focus, making it the active object.  Likewise, to remove a file, the object must be given focus.  To remove a file, open the Project window, click the file to remove, and choose File, Remove and the name of the file to remove will also appear.  An alternative is to display the Project Explorer, click the file that you want to delete, and right-click to produce the shortcut menu shown in Figure 2.3.  We discuss the concept of focus at length later.  There are even unique events, such as Gotfocus and LostFocus, that deal with this issue.

Figure 2.3 Display the Project Explorer and right-click to reveal several file optiions, including a command for removing a file from a project.

Exercise 2.2  Using the Remove and Add Commands

This exercise assumes that you completed Exercise 2.1 and saved the form as F2-1.frm.

  1. Open a new Standard EXE project, and change the name of the project to Project2_2 (click Project, Project1 Properties).
  2. Choose Project, Remove Form1.Form1 must have the focus because it is the only object assigned to the project.
  3. Choose Project, Add File.  Navigate through Windows to the location where you saved F2-1.frm, and add this form to your Project (see Figure 2.4).

    Figure 2.4

    The Add File dialog box lists saved forms that can be added to a project.

  4. Open the Project Explorer Window, and give form F2-1.frm the focus.
  5. Choose File, Save File As (or click the right mouse button).  When the dialog box opens, navigate to the location where you want to save the file, and name it F2-2.frm.
  6. Open the Project Window again and observe what happens.  The name of the form has been changed and assigned to the new project.
  7. Choose File, Save Project As.  In this instance, you are not asked to name the form because it has already been named and saved.  Instead, you are asked only to name the project, which we named P2-2.vbp.

Other File Menu Commands

Besides the four Project menu commands and the two file commands found on the File menu, the latter also contains the Print and Print Setup commands and the Make Project1.Exe commands, as follows:

  • Print – Choose File, Print to display several options for printing information about a project (see Figure 2.5).  You can print the form image, code, or the form as text, and you can choose to print information for a module or for the entire project.
  • Print Setup – Choose File, Print Setup to launch the standard Windows Print Setup dialog box.
  • Make Project1.Exe – Choose File, Make Project.Exe to create an executable application.  Project modules are compiled into a single .EXE file.  This file is either a P-Code interpreted executable or a native code executable file.  (The two code formats are explained in “Interpreted P-Code,” and “Compiled Native Code,” later.)

Both types of executables require runtime files.  The Visual Basic Setup Wizard can help you determine which runtime file your application requires.

Figure 2.5 The Print-Project dialog box enables you to choose the parts of an application that you want to print.

Exercise 2.3  Using the Print Command

This exercise is designed to show you the type of information printed for a project.

  1. Open a new Standard EXE project.
  2. Choose File, Print.
  3. When the dialog box appears, click Current Project, Form Image, Code and Form as Text.
  4. Click OK.

What is the difference between the Form Image and the Form as Text choice!  Why is there no computer code?

Share:

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