Testing Your User Control

In this lesson, you will learn how to test your user control in another project and observe its run-time behavior.

Run-Time Behavior

Once you have completed your user control and tested its design-time behavior in the TestContainer, you will also want to see how it behaves when used in a program. Visual Basic makes it easy to test your user control by adding a Windows Application project.

Your user control automatically appears in the Toolbox, and you can add it to a form and set its properties just as you would with any other control.

Try It!

To test your user control

  1. Open the NamesUserControl project that you created in the previous lesson. If you did not save it, you will first need to go back to the previous lesson, Adding Code to Your User Control, and complete the procedures in that lesson.

  2. On the File menu, point to Add and click New Project.

  3. In the Add New Project dialog box, select Windows Application.

  4. In the Name box, type UserControlTest, and then click OK.

    A new project will be added in Solution Explorer, and a new form will be displayed.

  5. In Solution Explorer, select the UserControlTest project, and on the Project menu, select Set as StartUp Project.

  6. In the Toolbox, select NamesControl and drag it to the form.

  7. In the Properties window, set the FirstNameText, MiddleNameText, and LastNameText properties to match your name.

  8. Press F5 to run the program. Change the names in the text boxes to make sure the label updates correctly.

  9. On the File menu, choose Save All to save your work.

Next Steps

In this lesson, you learned how to add your user control to a form and observe its run-time behavior. At this point, you can learn more about user controls in Closer Look: Customizing Your User Control, or you can go on to the next group of lessons and learn about graphics.

Next Lesson: Drawing Pictures: Using Graphics

See Also

Tasks

Adding Code to Your User Control

Other Resources

Visible Objects: Creating Your First User Control

Programming with Objects: Using Classes

Visual Basic Guided Tour