Adding Controls to Your User Control

In this lesson, you will learn how to add controls to create a composite user control.

As mentioned earlier, the most common type of user control is a composite control—one that is made up of one or more standard Windows Forms controls. Controls can be added to a User Control template by dragging them from the Toolbox to the User Control Designer, just as you would do when designing a form.

Once you have added a control, you can resize it and move it in the designer, and you can set its properties in the Properties window.

For this example, you will add a Label control to display a full name, and three TextBox controls for entering first, last, and middle names.

To add controls to a 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, Understanding the User Control Designer, and complete the procedures in that lesson.

  2. In Solution Explorer, select NamesControl.vb, and then on the View menu, choose Designer.

  3. From the Toolbox, drag a Label control onto the designer.


    The Toolbox is easier to use if you keep the window open. You can do this by clicking the Auto Hide icon, which looks like a push pin.

  4. In the Properties window, change the Name property to FullName.

  5. From the Toolbox, drag three TextBox controls onto the designer. You can arrange them however you like.

  6. In the Properties window, change their Name properties to FirstName, MiddleName, and LastName.

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

In this lesson, you learned how to add controls in the User Control Designer and set their properties. Now you are ready to add to your control so that it actually performs a useful task. The next lesson shows you how to write code that will direct your user control to display first, middle, and last names, as well as expose new properties.

Next Lesson: Adding Code to Your User Control.