813450 How to: Use Visual C # .NET to make UserControl a design-time control container (from MSDN)

xiaoxiao2021-03-06  68

For Microsoft Visual Basic .NET versions of this article, see

322222.

This article references the following Microsoft .NET Framework Class Bank Name Space:

System.componentmodel

This task content

summary

Overview Create UserControl to Design Control Container Test UserControl Reference

Summary This step-by-step guide introduces

UserControl is placed on a Windows form, how

UserControl objects are used as design-hours control containers. There may be such a situation: you want to drag a control to

UserControl. To do this,

UserControl must be used as a control container.

Back to top

Overview

by default,

UserControl objects can only be used as control containers when you create it. In

UserControl is placed on the Windows form,

UserControl carries the constituent control, you must change

UserControl's default designer. To implement design-time service for a component, please use

System.ComponentModel namespace

DesigneRATITRIBUTE class.

Designerattribute appears in front of the class declaration. Pass through

Designertypename and

Designerattribute parameter initialization

Designertypename.

Designertypename is a fully qualified name of the designer type for design-time service. transfer

Designertypename parameters

System.windows.Forms.Design.ParentControlDesigner and

The combination of System.Design.

The ParentControlDesigner class extends

UserControl design time behavior.

DesignerBaseType is the name of the base class of the designer. Classes for design-hours must implement the IDesigner interface.

Back to top

Create UserControl as a design control container

Create a new Visual C # .NET Windows control library project. To do this, follow these steps:

Start Visual Studio .NET. On the File menu, point to "New" and click Project. Under Project Types, click Visual C # items, and then click Windows Control Library under Templates. Name the project ContainerControl. "UserControl1.cs" will be created by default. In the Solution Explorer, right-click "UserControl1.cs" and click View Code. Add the following code to the Declarations section: using System.ComponentModel.Design; System.ComponentModel.DesignerAttribute shown in the following properties to the control: [Designer ( "System.Windows.Forms.Design.ParentControlDesigner, System.Design", TypeOf (iDesigner)] public class userControl1: system.windows.forms.userControl {

...

} On the Generate menu, click Generate Solutions.

Back to top

Test UserControl

Create a new Visual C # item. To do this, follow these steps:

Start Visual Studio .NET. On the File menu, point to "New" and click Project. Under Project Types, click Visual C # items, and then click Windows Applications under Modular. "Form1.cs" will be created by default. Drag "UserControl1" from the toolbox (under "Windows Form") to "Form1.cs". Drag a button control from the toolbox to "UserControl1". You will notice that "UserControl1" acts as a control container for button controls. Back to top

Refer to more information, please visit the Microsoft Web site below:

ParentControlDesigner Classhttp: //msdn.microsoft.com/library/default.asp url = / library / en-us / cpref / html / frlrfsystemwindowsformsdesignparentcontroldesignerclasstopic.aspDesignerAttribute Classhttp:? //Msdn.microsoft.com/library/default.asp url? = / library / en-us / cpref / html / frlrfsystemComponentModeldesignerattributeClasstopic.asp

Back to top

The information in this article applies to:

Microsoft Visual C # .NET (2002)

Recent Update: 2003-6-9 (1.0) Keyword KBControl Kbcontainer KbwindowsForms KbcompModel KbhowTomaster KB813450 KBAUDDEVELOPER

转载请注明原文地址:https://www.9cbs.com/read-108994.html

New Post(0)