방법: 디자인 모드에서 컨트롤에 대한 사용자 지정 초기화 수행

구성 요소 및 컨트롤을 디자인 환경에서 만들 때 사용자 지정 디자이너를 사용하여 초기화할 수 있습니다.

예제

다음 코드 예제에서는 컨트롤을 디자인 환경에서 만들 때 초기화하는 방법을 보여 줍니다. 컨트롤의 인스턴스를 폼으로 끌 때와 디자이너에서 폼을 시작할 때에도 이 코드를 만들 수 있습니다. 이 코드 예제에 대한 자세한 설명을 보려면 방법: 디자인 모드에서 컨트롤의 모양과 동작 확장을 참조하십시오.

' This demonstrates changing the appearance of a control while 
' it is being designed. In this case, the BackColor property is 
' set to LightBlue.  
Public Overrides Sub InitializeNewComponent( _
ByVal defaultValues As IDictionary)

    MyBase.InitializeNewComponent(defaultValues)

    Dim colorPropDesc As PropertyDescriptor = _
    TypeDescriptor.GetProperties(Component)("BackColor")

    If colorPropDesc IsNot Nothing AndAlso _
       colorPropDesc.PropertyType Is GetType(Color) AndAlso _
       Not colorPropDesc.IsReadOnly AndAlso _
       colorPropDesc.IsBrowsable Then
        colorPropDesc.SetValue(Component, Color.LightBlue)
    End If 
End Sub
// This demonstrates changing the appearance of a control while 
// it is being designed. In this case, the BackColor property is 
// set to LightBlue.  

public override void InitializeNewComponent(IDictionary defaultValues)
{
    base.InitializeNewComponent(defaultValues);

    PropertyDescriptor colorPropDesc = 
        TypeDescriptor.GetProperties(Component)["BackColor"];

    if (colorPropDesc != null &&
        colorPropDesc.PropertyType == typeof(Color) &&
        !colorPropDesc.IsReadOnly &&
        colorPropDesc.IsBrowsable)
    {
        colorPropDesc.SetValue(Component, Color.LightBlue);
    }
}

디자인 환경에서 컨트롤이나 구성 요소의 인스턴스를 만들 때 디자이너의 InitializeNewComponent 메서드를 호출합니다. 이전의 코드 예제에서 컨트롤의 BackColor 속성은 PropertyDescriptor를 통해 설정됩니다.

코드 컴파일

구성 요소의 디자인 타임 측면을 변경한 경우 컨트롤 프로젝트를 다시 빌드해야 합니다. 또한, 현재 열려 있고 이 구성 요소를 사용하는 다른 Windows Forms 프로젝트가 있는 경우 변경 내용을 보려면 프로젝트에 대한 새로 고침을 수행해야 합니다. 일반적으로 구성 요소가 있는 디자인 창을 닫고 다시 열어야 합니다.

참고

디자인 타임 어셈블리 System.Design.dll에 대한 참조를 추가해야 합니다.이 어셈블리는 .NET Framework 4 Client Profile에 포함되지 않습니다.System.Design.dll에 대한 참조를 추가하려면 프로젝트의 대상 프레임워크를 .NET Framework 4로 변경해야 합니다.

참고 항목

작업

방법: 디자인 모드에서 컨트롤의 모양과 동작 확장

기타 리소스

사용자 지정 디자이너