Files
docs-desktop/dotnet-desktop-guide/framework/winforms/controls/how-to-author-composite-controls.md
T
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

3.8 KiB

title, ms.date, helpviewer_keywords, ms.assetid, author, ms.author, manager
title ms.date helpviewer_keywords ms.assetid author ms.author manager
How to: Author Composite Controls 03/30/2017
UserControl class [Windows Forms], creating composite controls
user controls [Windows Forms], creating
user controls [Windows Forms], inheriting from
composite controls [Windows Forms], creating
79c9cf05-5ab6-4a18-886d-88a64748b098 jillre jillfra jillfra

How to: Author composite controls

Composite controls can be employed in many ways. You can author them as part of a Windows desktop application project, and use them only on forms in the project. Or you can author them in a Windows Control Library project, compile the project into an assembly, and use the controls in other projects. You can even inherit from them and use visual inheritance to customize them quickly for special purposes.

To author a composite control

  1. In Visual Studio, create a new Windows Application project, and name it DemoControlHost.

  2. On the Project menu, click Add User Control.

  3. In the Add New Item dialog box, give the class file (.vb or .cs file) the name you want the composite control to have.

  4. Select the Add button to create the class file for the composite control.

  5. Add controls from the Toolbox to the composite control surface.

  6. Place code in event procedures, to handle events raised by the composite control or by its constituent controls.

  7. Close the designer for the composite control, and save the file when you are prompted.

  8. On the Build menu, click Build Solution.

    The project must be built in order for custom controls to appear in the Toolbox.

  9. Use the DemoControlHost tab of the Toolbox to add instances of your control to Form1.

To author a control class library

  1. Open a new Windows Control Library project.

    By default, the project contains a composite control.

  2. Add controls and code as described in the procedure above.

  3. Choose a control you do not want inheriting classes to change, and set the Modifiers property of this control to Private.

  4. Build the DLL.

To inherit from a composite control in a control class library

  1. On the File menu, point to Add and select New Project to add a new Windows Application project to the solution.

  2. In Solution Explorer, right-click the References folder for the new project and choose Add Reference to open the Add Reference dialog box.

  3. Select the Projects tab and double-click your control library project.

  4. On the Build menu, click Build Solution.

  5. In Solution Explorer, right-click your control library project and select Add New Item from the shortcut menu.

  6. Select the Inherited User Control template from the Add New Item dialog box.

  7. In the Inheritance Picker dialog box, double-click the control you want to inherit from.

    A new control is added to your project.

  8. Open the visual designer for the new control and add additional constituent controls.

    You can see the constituent controls that were inherited from the composite control in your DLL, and you can alter the properties of controls whose Modifiers property is Public. You cannot change the properties of the control whose Modifiers property is Private.

See also