How to: Test the run-time behavior of a UserControl
When you develop a UserControl, you need to test its run-time behavior. You can create a separate Windows-based application project and place your control on a test form, but this procedure is inconvenient. A faster and easier way is to use the UserControl Test Container provided by Visual Studio. This test container starts directly from your Windows control library project.
Important
For the test container to load your UserControl, the control must have at least one public constructor.
Note
A Visual C++ control cannot be tested using the UserControl Test Container.
Test the run-time behavior of a UserControl
In Visual Studio, create a Windows control library project, and name it TestContainerExample.
In the Windows Forms Designer, drag a Label control from the Toolbox onto the control's design surface.
Press F5 to build the project and run the UserControl Test Container. The test container appears with your UserControl in the Preview pane.
Select the BackColor property displayed in the PropertyGrid control to the right of the Preview pane. Change its value to ControlDark. Observe that the control changes to a darker color. Try changing other property values and observe the effect on your control.
Click the Dock Fill User Control check box below the Preview pane. Observe that the control is resized to fill the pane. Resize the test container and observe that the control is resized with the pane.
Close the test container.
Add another user control to the TestContainerExample project.
In the Windows Forms Designer, drag a Button control from the Toolbox onto the control's design surface.
Press F5 to build the project and run the test container.
Click the Select User Control ComboBox to switch between the two user controls.
Test user controls from another project
You can test user controls from other projects in your current project's test container.
In Visual Studio, create a Windows control library project, and name it TestContainerExample2.
In the Windows Forms Designer, drag a RadioButton control from the Toolbox onto the control's design surface.
Press F5 to build the project and run the test container. The test container appears with your UserControl in the Preview pane.
Click the Load button.
In the Open dialog box, navigate to TestContainerExample.dll, which you built in the previous procedure. Select TestContainerExample.dll and click the Open button to load the user controls.
Use the Select User Control ComboBox to switch between the two user controls from the TestContainerExample project.
See also
.NET Desktop feedback