This course - About Custom Controls

last updated: 08/07/2006

What are custom controls?

A control is a reusable component such as a textbox, label, or drop-down list. Many standard controls come built into .NET, and you can inherit from ("extend") these controls to accomplish many useful things.
 

Why would you use one?


Two ways of using custom controls

  1. Use the Windows Forms Designer and the Toolbox to drag custom controls onto a form

    This is for visual, manual placement on a form by dragging and resizing. For this case, these are the basic steps:
    • Use the New Project wizard to create a Windows Control Library project.
    • Edit the custom control class to do what you want.
    • Build the project (which compiles to a .dll file).
    • Add the custom control .dll to the Toolbox.
    • Drag the custom control from the Toolbox onto the form.

    Please work through Tutorial 1 to try the above.
     
  2. Add custom controls by writing code (important if there are many identical controls)

    This is typically used for the information storage type. If you have to send individual information to each control when it's instantiated, you'll have to write code to do it. For this case, these are the basic steps:
    • Add a UserControl class to your project.
    • Edit the custom control class to do what you want.
    • Write code explicitly to add the custom control to your form.

    Please work through Tutorial 2 to try the above.
     



Visitors: Hit Counter