특성 및 디자인 타임 지원

업데이트: 2007년 11월

디자인 타임 지원 확장은 일반적으로 구성 요소에 대한 코드와 별도로 존재하는 코드로 구현됩니다. 또한 다양한 특성을 사용하여 디자인 타임 지원 공급자를 형식 또는 개별 형식 멤버에 연결합니다.

디자인 타임 지원 연결에 대한 특성

DesignerAttribute는 디자이너를 형식에 연결합니다. TypeConverterAttribute는 형식 변환기를 형식이나 형식 멤버에 연결합니다. EditorAttribute는 UI 형식 편집기를 형식이나 형식 멤버에 연결합니다.

구성 요소 초기화 사용자 정의에 대한 특성

DefaultValueAttribute를 속성에 적용하여 구성 요소가 디자인 타임에 로드될 때 속성의 기본값을 지정할 수 있습니다. DefaultValueAttribute를 지정하면 디자인 타임에 구성 요소 초기화 코드에서 설정한 값이 재정의되지만 디자이너에서 설정한 값은 재정의되지 않습니다.

속성 창 동작 사용자 지정에 대한 특성

BrowsableAttribute를 적용하여 속성이나 이벤트를 속성 창에 나열할지 여부를 지정할 수 있습니다. 또한 IDesignerFilter 인터페이스를 구현하는 디자이너를 사용하면 디자인 타임에 속성 창에 노출된 속성 및 이벤트 집합을 수정할 수 있습니다. CategoryAttribute를 속성이나 이벤트에 적용하여 속성 창에서 속성이나 이벤트가 나열되는 범주를 지정할 수 있습니다. 또한 DescriptionAttribute를 속성이나 이벤트에 적용하여 속성 창에 표시될 속성이나 이벤트에 대한 설명을 지정할 수 있습니다.

DesignOnlyAttribute를 속성에 적용하여 디자인 타임에만 속성을 설정할 수 있는지 여부를 지정할 수 있습니다. ReadOnlyAttribute를 속성에 적용하여 디자인 타임에 속성이 읽기 전용인지, 아니면 읽기/쓰기인지를 지정할 수 있습니다.

ParenthesizePropertyNameAttribute를 true 값으로 지정하여 속성에 적용하면 속성 창에서 속성 이름을 괄호로 묶을지 여부를 지정할 수 있습니다.

알림을 발생시키는 중첩된 속성에 NotifyParentPropertyAttribute를 적용하여 중첩된 속성의 값이 변경될 때 중첩된 속성을 포함하거나 자식 속성을 포함하는 속성에 이를 알릴지 여부를 지정할 수 있습니다.

적절한 RefreshProperties 값이 지정된 RefreshPropertiesAttribute를 속성이나 이벤트에 적용하여 구성 요소에 대한 속성을 새로 고칠지, 속성을 새로 고치지 않을지 또는 디자이너 뷰를 다시 그릴지를 지정할 수 있습니다.

디자인 타임 Serialization 동작 사용자 정의에 대한 특성

적절한 DesignerSerializationVisibility 열거형 값이 지정된 DesignerSerializationVisibilityAttribute를 속성에 적용하여 속성 값 또는 컬렉션 속성 값을 serialize할지 여부를 지정할 수 있습니다. Visual Studio에서는 이 작업을 폭넓게 지원합니다.

한편 SerializableAttribute를 형식에 적용하여 형식을 serialize할 수 있는지 여부를 지정할 수 있습니다. ISerializable 인터페이스를 구현하거나 사용자 지정 serializer를 제공하여 사용자 지정 serialization을 제공할 수 있습니다. serialization에 대한 자세한 내용은 Serialization을 참조하십시오.

일반적으로 사용되는 디자인 타임 특성에 대한 자세한 내용은 구성 요소의 디자인 타임 특성을 참조하십시오.

특성 적용

디자인 타임 특성은 속성, 이벤트, 클래스 및 어셈블리에도 적용됩니다. 다음 코드 예제에서는 클래스에 적용되는 특성 다음에 속성 및 이벤트에 적용되는 특성을 보여 줍니다.

' The attribute is the element in angle brackets, and the parameters 
' in the attribute syntax are arguments of the constructor 
' of the attribute class.
' 
' Attributes applied at the class level.
<DefaultEvent("ValueChanged"), _
DefaultProperty("Number")> _
Public Class MyControl
   Inherits Control   
   ...
   ' Attribute applied to a property.
   <DefaultValue(False)> _
   Public Shadows ReadOnly Property TabStop() As Boolean
      ...
   End Property
   
   ' Attribute applied to a property.
   <CategoryAttribute("Data")> _
   Public ReadOnly Property Number() As Integer
      ...
   End Property 
   
   ' Attribute applied to an event.
   <Description("Raised when the Value displayed changes.")>  _
   Public Event ValueChanged As EventHandler
   ...
End Class
// The attribute is the element in brackets, and the parameters in 
// the attribute syntax are arguments of the constructor 
// of the attribute class.
// 
// Attributes applied at the class level.
[DefaultEvent("ValueChanged")]
[DefaultProperty("Number")]
public class MyControl : Control {
   ...
   // Attribute applied to a property.
   [DefaultValue(false)]
   public new bool TabStop {...
   }

   // Attribute applied to a property.
   [CategoryAttribute("Data")]
   public int Number {...}

   // Attribute applied to an event.
   [Description("Raised when the Value displayed changes.")]
   public event EventHandler ValueChanged;
}

규칙에 따라 특성 클래스는 AttributeNameAttribute로 명명됩니다. System.ComponentModel 네임스페이스에는 많은 기본 특성 클래스가 포함됩니다.

디자인 타임 특성 및 상속

디자인 타임 특성이 있는 기본 구성 요소에서 구성 요소 또는 컨트롤이 파생될 때, 사용자의 구성 요소는 기본 클래스의 디자인 타임 기능을 상속합니다. 기본 기능이 사용자의 목적에 맞으면 특성을 다시 적용할 필요가 없습니다. 그러나 같은 형식의 특성을 재정의하거나 파생된 구성 요소에 추가 특성을 적용할 수 있습니다. 다음 코드 구문에서는 기본 클래스에 적용된 BrowsableAttribute 특성을 재정의하여 Control에서 상속된 Text 속성을 재정의하는 사용자 지정 컨트롤을 보여 줍니다.

Public Class MyControl
   Inherits Control
   ' The base class has [Browsable(true)] applied to the Text property.
   <Browsable(False)>  _
   Public Overrides Property [Text]() As String
      ...
   End Property 
   ...
End Class
public class MyControl : Control {
// The base class has [Browsable(true)] applied to the Text property.
[Browsable(false)]
 public override string Text {...}
...
}

형식 변환기, UI 형식 편집기 또는 디자이너 특성 적용

디자인 타임 지원 공급자를 형식이나 형식 멤버에 연결하려면 클래스 또는 멤버 선언의 앞에 있는 줄에 적절한 특성 형식을 적용합니다. 다음 코드 예제에서는 형식에 적용되는 TypeConverterAttribute를 보여 줍니다.

<TypeConverter(GetType(MyColorConverter)), _
Editor(GetType(MyColorEditor), GetType(UITypeEditor))> _
Structure MyColor
   ...
End Structure
[ TypeConverter(typeof(MyColorConverter))]
[ Editor(typeof(MyColorEditor), typeof(UITypeEditor))] 
struct MyColor {...}

속성 형식에 해당 속성 형식과 연결된 형식 변환기나 UI 형식 편집기가 없는 경우, 또는 속성 형식과 연결된 기본 형식 변환기나 UI 형식 편집기를 재정의하려는 경우에는 속성 자체에 특성을 적용할 수 있습니다. 형식 변환기를 속성과 연결하려면 다음 코드 예제에서처럼 속성 선언에 TypeConverterAttribute를 적용합니다.

<TypeConverter(GetType(PointConverter))> _
Public Property MyLocation() As Point
   ...
End Property       
[ TypeConverter(typeof(PointConverter))]
        public Point MyLocation {...}  

UI 형식 편집기를 속성과 연결하려면 다음 코드 예제에서처럼 EditorAttribute를 속성에 적용합니다.

<Editor(GetType(FlashTrackBarDarkenByEditor), _
GetType(UITypeEditor))>  _
Public Property DarkenBy() As Byte
   ...
End Property
[ Editor(typeof(FlashTrackBarDarkenByEditor), typeof(UITypeEditor))]
        public byte DarkenBy {...}

디자이너는 형식에는 연결할 수 있지만 속성에는 연결할 수 없습니다. 디자이너를 형식과 연결하려면 다음 코드 예제에서처럼 클래스 선언 위에서 DesignerAttribute를 직접 적용합니다.

<Designer(GetType(HelpLabel.HelpLabelDesigner))> _
Public Class HelpLabel
   Inherits System.Windows.Forms.Control
   Implements System.ComponentModel.IExtenderProvider
   ...
End Class
    [Designer(typeof(HelpLabel.HelpLabelDesigner))]
    public class HelpLabel : System.Windows.Forms.Control, System.ComponentModel.IExtenderProvider {...}
참고:

위 예제에서 TypeConverterAttribute,EditorAttributeDesignerAttribute 클래스의 생성자는 System.Type 개체를 인수로 받습니다. 형식이 디자인 타임 클래스와 같은 어셈블리에 있으면 이 특성에 대한 이와 같은 형태의 생성자가 사용됩니다. 디자인 타임 클래스가 다른 어셈블리에 있을 경우, 다음 코드 예제에서처럼 다른 형식의 특성 생성자(어셈블리로 한정된 형식)가 필요합니다.

<Designer("System.Windows.Forms.Design.DocumentDesigner, System.Design")>  _
Public Class MyForm
   Inherits Form
   ...
End Class
[Designer("System.Windows.Forms.Design.DocumentDesigner, System.Design")]
public class MyForm : Form {...}

어셈블리 수준의 디자인 타임 특성

ASP.NET에서는 컨트롤 개발자가 ASP.NET 컨트롤에 태그 접두사를 지정할 수 있도록 해 주는 어셈블리 수준의 특성(System.Web.UI.TagPrefixAttribute)을 제공합니다. 태그 접두사는 Visual Studio .NET에서 컨트롤의 Register 지시문에 자동으로 삽입됩니다. 따라서 컨트롤은 미리 지정된 태그 접두사(<tagprefix:controlname runat = server />)를 사용하여 페이지에서 선언적으로 사용될 수 있습니다.

참고:

TagPrefixAttribute는 비주얼 디자이너에서만 작동합니다. 메모장과 같은 텍스트 편집기를 사용하여 ASP.NET 페이지를 제작하려면, 사용자가 컨트롤의 Register 지시문에 태그 접두사 및 네임스페이스를 직접 지정해야 합니다.

다음 코드 예제에서는 TagPrefixAttribute를 적용하는 방법을 보여 줍니다. 특성 생성자에 대한 첫 번째 인수는 네임스페이스를 지정하고, 두 번째 인수는 태그 접두사를 지정합니다.

<assembly: TagPrefix("SimpleControls", "simple")>
Namespace SimpleControls
   <Designer("SimpleControl.Design.SimpleDesigner, SimpleControl")>  _
   Public Class SimpleControl
      Inherits System.Web.UI.WebControls.WebControl
      ...
   End Class 
End Namespace
[ assembly:TagPrefix("SimpleControls", "simple") ]
namespace SimpleControls {
    [
        Designer("SimpleControl.Design.SimpleDesigner, SimpleControl")
    ]
    public class SimpleControl : System.Web.UI.WebControls.WebControl {}
}

참고 항목

작업

방법: 형식 변환기 구현

방법: UI 형식 편집기 구현

방법: Windows Forms 컨트롤에서 특성 적용

개념

Windows Forms 컨트롤의 특성

구성 요소의 디자인 타임 특성

기타 리소스

디자인 타임 지원 확장

사용자 지정 디자이너