???? ID: 813450 - ????? ???????: 05 ?????? 2010 - ??????: 2.0

????? ???? ?? UserControl ???????? ?? ????? ?? ??? ???? ?? ?? ???????? ???????? ???????-???? ?? ??? ??? ????? C# ?? ????? ??

?????? ??????This article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.

?? ????? ??

??? ?? ??????? ???? | ??? ?? ??????? ????

??????

?? ??? ?? ??? ???? ????? ?? ?? ???? ????? ?? ??? ???UserControlact ?? ??? ??? ?? ???? ?? ??? ??????-??? ?? ??? ???????? ???????? ??? ????????UserControl?? Windows ???????? ???? ?? ???? ???????? ???? ?? ??? ?????? ????????? ?? ???? ?? ????UserControl. To do this, theUserControlmust act as a control container.

????????? ??????


By default, aUserControlobject can act as a control container only when you create the control. To make aUserControlhost a constituent control after you put theUserControlon a Windows Form, you must change the default designer of theUserControl. To implement design-time services for a component, use theDesignerAttribute?? ????System.ComponentModel??? ????? ??? TheDesignerAttributecomes before the class declaration. ???????DesignerAttributeby passing thedesignerTypeName??designerBaseType?????????

designerTypeNameis the fully qualified name of the designer type that provides design-time services. Pass the combination of theSystem.Windows.Forms.Design.ParentControlDesigner??System.Design?? ???designerTypeName????????? TheParentControlDesignerclass extends design-time behavior for aUserControl.

designerBaseTypeis the name of the base class for the designer. The class that is used for the design-time services must implement the IDesigner interface.


Create the UserControl as a Design-Time Control Container

  1. Create a new Visual C# Windows Control Library project. ??? ???? ?? ???, ????? ????? ?? ???? ????::
    1. Visual Studio ??????? ?????
    2. ????? ???????????? ??,????? ????-????? ????, ?? ???? ????????????.
    3. ?? ???????????????? ??????????? ????,????? C#?? ????-????? ????, ?? ???? ???Windows Forms Control Library?? ???????????????.

      ???:Visual Studio 2003, ????? ????????? C# ??????????? ???????????????? ???????? ????-????? ????, ?? ???? ???Windows ???????? ??????????? ???????????????.
  2. ????????? ?? ???ContainerUserControl. ???????? ??? ??,UserControl1.cs????? ??? ???
  3. ?????? Explorer ???, ???? ?????UserControl1.cs?? ????-????? ????, ?? ???? ???????? ???.
  4. Add the following code to the Declarations section:
    using System.ComponentModel.Design;
  5. ???? ????System.ComponentModel.DesignerAttributeattribute to the control as follows:
    [Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))] 
    public class UserControl1 : System.Windows.Forms.UserControl
    {
    
          ...
    
    }
  6. ????? ????????????? ??,??????? ??????.


Test the UserControl

  1. Create a new Visual C# project. ??? ???? ?? ???, ????? ????? ?? ???? ????::
    1. Visual Studio ??????? ?????
    2. ????? ???????????? ??,????? ????-????? ????, ?? ???? ????????????.
    3. ?? ???????????????? ??????????? ????,????? C#?? ????-????? ????, ?? ???? ???Windows Forms Application?? ???????????????. ???????? ??? ??,Form1.cs????? ??? ???

      ???:Visual Studio 2003, ????? ????????? C# ??????????? ???????????????? ???????? ????-????? ????, ?? ???? ???Windows ???????? ??????????? ???????????????.
  2. ?????UserControl1control to the toolbox.
    1. ????? ????????????? ??,????? ????? ???? ?????.
    2. ????? ????.NET ????? ?????? ??,???????.
    3. ?????????? ?????????? ???, ???? ?????? ????? ??? ?? ????? ??? ?? ?? DLL ?? ??? ???UserControl???????? ???
  3. ??????UserControl1????? ????? ?? (???? Windows ???????) ?? ??? ??Form1.cs.
  4. ?????? ???????????? ????? ?? ??? ?? ????????? ????UserControl1.
  5. ?? ?????UserControl1?? ??? ???????? ???????? ?? ??? ??? ??????? ???? ????????????? ???

??????

???? ??????? ?? ???, ????? Microsoft ??? ???? ?????:

ParentControlDesigner ????
(VS.71) http://MSDN.Microsoft.com/en-us/library/SYSTEM.Windows.forms.design.parentcontroldesigner .aspx (http://msdn.microsoft.com/en-us/library/system.windows.forms.design.parentcontroldesigner(VS.71).aspx)

DesignerAttribute ????
(vs.71) http://MSDN.Microsoft.com/en-us/library/SYSTEM.componentmodel.designerattribute .aspx (http://msdn.microsoft.com/en-us/library/system.windows.forms.design.parentcontroldesigner(VS.71).aspx)



???? ???? ???? ??:
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft Visual C# 2005 Express Edition
  • Microsoft Visual C# 2008 Express Edition
??????: 
kbcontrol kbcontainer kbwindowsforms kbcompmodel kbhowtomaster kbmt KB813450 KbMthi
???? ?????? ???????????? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:813450  (http://support.microsoft.com/kb/813450/en-us/ )