To test a user control, you must first build the control to make it available to other projects, using the Build|Build Solution menu item. Then you can add a new Windows application to the solution to test the user control. To add the user control to the test application, right-click the References item of the test application in the Solution Explorer and select the Add Reference item. After adding a reference to the user control, drag the user control from the toolbox to the main form of the test application, set the properties of the user control as you like, and run the test application.
In the UserControls example discussed in the In Depth section of this chapter, we did that by creating a new application named TestApplication, which tested the user control's DisplayColor property, SetText method, and TextModified event. To see how to add a user control to that test application, take a look at the discussion of that example in the In Depth section of this chapter. Here is the code for the main form in TestApplication that does all the work:
Public Class Form1 Inherits System.Windows.Forms.Form ' Windows Form Designer generated code... Private Sub Button1_Click(ByVal sender As System.Object, ByVal _ e As System.EventArgs) Handles Button1.Click UserControl11.SetText("Hello!") End Sub Private Sub UserControl11_TextModified(ByVal NewText As String) _ Handles UserControl11.TextModified TextBox1.Text = "New text: "& NewText End Sub End Class