Example of Sharing a Form Between Projects in VB for Windows

ID Number: Q81222

1.00

WINDOWS

Summary:

Microsoft Visual Basic allows you to share forms between projects.

When you make a change to a shared form in one project, that change

will be automatically updated in the other projects that share the

form.

A workaround is also available if you want to change a shared form but

do not want to update the form in other projects.

Further below is an example of how to use this shared form feature in

Visual Basic, and an example of how to change a shared form without

updating it in shared projects.

More Information:

Below are two examples: the first shows how to update shared forms,

and the second demonstrates how to change a shared form without having

those changes affect the same form in other projects.

Example 1

---------

1. Run Visual Basic, or from the File menu, choose New Project (ALT,

F, N) if Visual Basic is already running. Form1 is created by

default.

2. Add a couple text boxes and command buttons to Form1 by

double-clicking on the appropriate tools in the toolbox and placing

the controls at certain locations on the form. From the Properties

Bar, change the FormName property of Form1 to Test1.

3. From the File menu, choose Save Project As. Save Test1 as TEST1.FRM

and save the project as TEST1.MAK.

4. Start a new project by choosing New Project from the File menu.

5. From the File menu, choose Add File, and select TEST1.FRM.

6. Once TEST1.FRM is loaded into the project, delete the command

buttons, and replace them with picture boxes.

7. From the File menu, choose Save Project As. Save the project as

TEST2.MAK, and save TEST1.FRM with the same name.

8. From the File menu, choose Open Project. In the Files box, select

TEST1.MAK.

Notice that the form has been updated to include picture boxes and the

command buttons were deleted.

Example 2

---------

(Note that the following steps are very similar to the example above,

but with a change in step 5.)

This example demonstrates how to share forms between projects, but

with the forms being designed differently.

1. Run Visual Basic, or from the File menu, choose New Project (ALT,

F, N) if Visual Basic is already running. Form1 is created by

default.

2. Add a couple text boxes and command buttons to Form1 by

double-clicking on the appropriate tools in the toolbox and placing

the controls at certain locations on the form. From the Properties

Bar, change the FormName property of Form1 to Test3.

3. From the File menu, choose Save Project As. Save Test3 as TEST3.FRM

and save the project as TEST3.MAK.

4. From the File menu, choose New Project.

5. From the File menu, choose Add File. In the Files box, select

TEST3.FRM. Once the file is loaded, delete the command buttons

and replace them with picture boxes.

6. From the File menu, choose Save File As, and save the form as

TEST4.FRM.

7. From the File menu, choose Save Project As, and save the project as

TEST4.MAK.

8. From the File menu, choose Open Project. In the Files box, select

TEST3.MAK.

Notice that the form's controls have NOT been updated with picture

boxes.

Reference(s):

"Microsoft Visual Basic: Programmer's Guide," version 1.0, page 45

Additional reference words: 1.00