DesignerAutoFormatCollection 클래스

정의

컨트롤 디자이너 내에 있는 DesignerAutoFormat 개체의 컬렉션을 나타냅니다. 이 클래스는 상속될 수 없습니다.

public ref class DesignerAutoFormatCollection sealed : System::Collections::IList
public sealed class DesignerAutoFormatCollection : System.Collections.IList
type DesignerAutoFormatCollection = class
    interface IList
    interface ICollection
    interface IEnumerable
Public NotInheritable Class DesignerAutoFormatCollection
Implements IList
상속
DesignerAutoFormatCollection
구현

예제

다음 코드 예제를 구현 하는 방법에 설명 합니다 AutoFormats 사용자 지정 컨트롤 디자이너의 속성입니다. 파생된 컨트롤 디자이너 구현 합니다 AutoFormats 에서 파생 되는 사용자 지정 자동 서식 지정의 세 인스턴스를 추가 하 여 속성을 DesignerAutoFormat 클래스입니다.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.Design.WebControls;
using System.Web.UI.WebControls;

namespace CustomControls.Design.CS
{
    // A custom Label control whose contents can be indented
    [Designer(typeof(IndentLabelDesigner)), 
        ToolboxData("<{0}:IndentLabel Runat=\"server\"></{0}:IndentLabel>")]
    public class IndentLabel : Label
    {
        private int _indent = 0;

        // Property to indent all text within the label
        [Category("Appearance"), DefaultValue(0), 
            PersistenceMode(PersistenceMode.Attribute)]
        public int Indent
        {
            get { return _indent; }
            set
            {
                _indent = value;
                // Get the number of pixels to indent
                int ind = value * 8;

                //  Add the indent style to the control
                if (ind > 0)
                    this.Style.Add(HtmlTextWriterStyle.MarginLeft, ind.ToString() + "px");
                else
                    this.Style.Remove(HtmlTextWriterStyle.MarginLeft);
            }
        }
    }

    // A design-time ControlDesigner for the IndentLabel control
    [SupportsPreviewControl(true)]
    public class IndentLabelDesigner : LabelDesigner
    {
        private DesignerAutoFormatCollection _autoFormats = null;

        // The collection of AutoFormat objects for the IndentLabel object
        public override DesignerAutoFormatCollection AutoFormats
        {
            get
            {
                if (_autoFormats == null)
                {
                    // Create the collection
                    _autoFormats = new DesignerAutoFormatCollection();

                    // Create and add each AutoFormat object
                    _autoFormats.Add(new IndentLabelAutoFormat("MyClassic"));
                    _autoFormats.Add(new IndentLabelAutoFormat("MyBright"));
                    _autoFormats.Add(new IndentLabelAutoFormat("Default"));
                }
                return _autoFormats;
            }
        }

        // An AutoFormat object for the IndentLabel control
        private class IndentLabelAutoFormat : DesignerAutoFormat
        {
            public IndentLabelAutoFormat(string name) : base(name)
            { }

            // Applies styles based on the Name of the AutoFormat
            public override void Apply(Control inLabel)
            {
                if (inLabel is IndentLabel)
                {
                    IndentLabel ctl = (IndentLabel)inLabel;

                    // Apply formatting according to the Name
                    if (this.Name == "MyClassic")
                    {
                        // For MyClassic, apply style elements directly to the control
                        ctl.ForeColor = Color.Gray;
                        ctl.BackColor = Color.LightGray;
                        ctl.Font.Size = FontUnit.XSmall;
                        ctl.Font.Name = "Verdana,Geneva,Sans-Serif";
                    }
                    else if (this.Name == "MyBright")
                    {
                        // For MyBright, apply style elements to the Style property
                        this.Style.ForeColor = Color.Maroon;
                        this.Style.BackColor = Color.Yellow;
                        this.Style.Font.Size = FontUnit.Medium;

                        // Merge the AutoFormat style with the control's style
                        ctl.MergeStyle(this.Style);
                    }
                    else
                    {
                        // For the Default format, apply style elements to the control
                        ctl.ForeColor = Color.Black;
                        ctl.BackColor = Color.Empty;
                        ctl.Font.Size = FontUnit.XSmall;
                    }
                }
            }
        }
    }
}
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.Design
Imports System.Web.UI.Design.WebControls
Imports System.Web.UI.WebControls

Namespace CustomControls.Design

    ' A custom Label control whose contents can be indented
    <Designer(GetType(IndentLabelDesigner)), _
        ToolboxData("<{0}:IndentLabel Runat=""server""></{0}:IndentLabel>")> _
    Public Class IndentLabel
        Inherits System.Web.UI.WebControls.Label

        Dim _indent As Integer = 0

        <Category("Appearance"), DefaultValue(0), _
            PersistenceMode(PersistenceMode.Attribute)> _
        Property Indent() As Integer
            Get
                Return _indent
            End Get
            Set(ByVal Value As Integer)
                _indent = Value

                ' Get the number of pixels to indent
                Dim ind As Integer = _indent * 8

                ' Add the indent style to the control
                If ind > 0 Then
                    Me.Style.Add(HtmlTextWriterStyle.MarginLeft, ind.ToString() & "px")
                Else
                    Me.Style.Remove(HtmlTextWriterStyle.MarginLeft)
                End If
            End Set
        End Property

    End Class

    ' A design-time ControlDesigner for the IndentLabel control
    Public Class IndentLabelDesigner
        Inherits LabelDesigner

        Private _autoFormats As DesignerAutoFormatCollection = Nothing
        ' The collection of AutoFormat objects for the IndentLabel object
        Public Overrides ReadOnly Property AutoFormats() As DesignerAutoFormatCollection
            Get
                If _autoFormats Is Nothing Then
                    ' Create the collection
                    _autoFormats = New DesignerAutoFormatCollection()

                    ' Create and add each AutoFormat object
                    _autoFormats.Add(New IndentLabelAutoFormat("MyClassic"))
                    _autoFormats.Add(New IndentLabelAutoFormat("MyBright"))
                    _autoFormats.Add(New IndentLabelAutoFormat("Default"))
                End If

                Return _autoFormats
            End Get
        End Property

        ' An AutoFormat object for the IndentLabel control
        Public Class IndentLabelAutoFormat
            Inherits DesignerAutoFormat

            Public Sub New(ByVal name As String)
                MyBase.New(name)
            End Sub

            ' Applies styles based on the Name of the AutoFormat
            Public Overrides Sub Apply(ByVal inLabel As Control)
                If TypeOf inLabel Is IndentLabel Then
                    Dim ctl As IndentLabel = CType(inLabel, IndentLabel)

                    ' Apply formatting according to the Name
                    If Me.Name.Equals("MyClassic") Then
                        ' For MyClassic, apply style elements directly to the control
                        ctl.ForeColor = Color.Gray
                        ctl.BackColor = Color.LightGray
                        ctl.Font.Size = FontUnit.XSmall
                        ctl.Font.Name = "Verdana,Geneva,Sans-Serif"
                    ElseIf Me.Name.Equals("MyBright") Then
                        ' For MyBright, apply style elements to the Style object
                        Me.Style.ForeColor = Color.Maroon
                        Me.Style.BackColor = Color.Yellow
                        Me.Style.Font.Size = FontUnit.Medium

                        ' Merge the AutoFormat style with the control's style
                        ctl.MergeStyle(Me.Style)
                    Else
                        ' For the Default format, apply style elements to the control
                        ctl.ForeColor = Color.Black
                        ctl.BackColor = Color.Empty
                        ctl.Font.Size = FontUnit.XSmall
                    End If
                End If
            End Sub
        End Class
    End Class

End Namespace

설명

ControlDesigner 클래스 및 파생된 클래스를 정의 합니다 AutoFormats 속성을 DesignerAutoFormatCollection 개체. 컨트롤 개발자는 AutoFormats 속성 파생된 컨트롤 디자이너에서 사용자 지정 자동 서식 지정 스타일을 추가 하 고 비주얼 디자이너로 지원 되는 형식 컬렉션을 반환 합니다.

컬렉션 개체를 추가할 때에 동적으로 증가 합니다. 이 컬렉션의 인덱스는 0부터 시작 합니다. 사용 된 Count 속성 컬렉션에 얼마나 많은 자동 스타일 서식을 확인 하기 위해.

또한 사용 하 여를 DesignerAutoFormatCollection 메서드 및 속성을 다음 기능을 제공 합니다.

  • Add 단일 형식 컬렉션에 추가 하는 방법입니다.

  • Insert 컬렉션 내의 특정 인덱스에 형식을 추가 하는 방법입니다.

  • Remove 서식을 제거 하는 방법입니다.

  • RemoveAt 특정 인덱스에서 형식을 제거 하는 방법입니다.

  • Contains 특정 형식을 이미 컬렉션에 있는지 여부를 결정 하는 방법입니다.

  • IndexOf 컬렉션 내에서 형식의 인덱스를 검색 하는 방법입니다.

  • Item[] 속성을 가져오거나 배열 표기법을 사용 하 여 특정 인덱스 형식으로 설정 합니다.

  • Clear 컬렉션에서 서식을 모두 제거 하는 방법입니다.

  • Count 속성 컬렉션에 있는 형식의 수를 결정 합니다.

  • IndexOf 메서드를 컬렉션에 있는 서식의 위치를 가져옵니다.

생성자

DesignerAutoFormatCollection()

DesignerAutoFormatCollection 클래스의 새 인스턴스를 초기화합니다.

속성

Count

컬렉션에 있는 DesignerAutoFormat 개체의 수를 가져옵니다.

Item[Int32]

컬렉션의 지정된 인덱스에서 DesignerAutoFormat 개체를 가져오거나 설정합니다.

PreviewSize

런타임에 표시되는 것과 같은 컨트롤의 최대 외부 크기를 가져옵니다.

SyncRoot

DesignerAutoFormatCollection 개체에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 가져옵니다.

메서드

Add(DesignerAutoFormat)

컬렉션의 끝에 지정된 DesignerAutoFormat 개체를 추가합니다.

Clear()

컬렉션에서 서식을 모두 제거합니다.

Contains(DesignerAutoFormat)

지정된 서식이 컬렉션에 있는지 여부를 확인합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IndexOf(DesignerAutoFormat)

컬렉션에 있는 지정된 DesignerAutoFormat 개체의 인덱스를 반환합니다.

Insert(Int32, DesignerAutoFormat)

컬렉션의 지정된 인덱스에 DesignerAutoFormat 개체를 삽입합니다.

MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
Remove(DesignerAutoFormat)

컬렉션에서 지정된 DesignerAutoFormat 개체를 제거합니다.

RemoveAt(Int32)

컬렉션의 지정된 인덱스에서 DesignerAutoFormat 개체를 제거합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

ICollection.CopyTo(Array, Int32)

Array 개체가 Array 인터페이스로 캐스팅된 경우 특정 DesignerAutoFormatCollection 인덱스에서 시작하여 컬렉션의 요소를 ICollection 개체에 복사합니다.

ICollection.Count

DesignerAutoFormatCollection 개체가 ICollection 인터페이스로 캐스팅된 경우 컬렉션에 포함된 요소의 수를 가져옵니다.

ICollection.IsSynchronized

DesignerAutoFormatCollection 개체가 ICollection 인터페이스로 캐스팅된 경우 컬렉션에 대한 액세스가 동기화되어 스레드로부터 안전하게 보호되는지 여부를 나타내는 값을 가져옵니다.

IEnumerable.GetEnumerator()

IEnumerator 개체가 DesignerAutoFormatCollection 인터페이스로 캐스팅된 경우 컬렉션을 반복하는 IEnumerable 인터페이스를 반환합니다.

IList.Add(Object)

DesignerAutoFormatCollection 개체가 IList 인터페이스로 캐스팅된 경우 컬렉션에 항목을 추가합니다.

IList.Contains(Object)

DesignerAutoFormatCollection 개체가 IList 인터페이스로 캐스팅된 경우 컬렉션에 특정 값이 있는지 여부를 확인합니다.

IList.IndexOf(Object)

DesignerAutoFormatCollection 개체가 IList 인터페이스로 캐스팅된 경우 컬렉션에서 특정 항목의 인덱스를 확인합니다.

IList.Insert(Int32, Object)

DesignerAutoFormatCollection 개체가 IList 인터페이스로 캐스팅된 경우 컬렉션의 지정된 인덱스에 항목을 삽입합니다.

IList.IsFixedSize

DesignerAutoFormatCollection 개체가 IList 인터페이스로 캐스팅된 경우 컬렉션의 크기가 고정되어 있는지 여부를 나타내는 값을 가져옵니다.

IList.IsReadOnly

메서드에 대한 설명은 IsReadOnly를 참조하십시오.

IList.Item[Int32]

DesignerAutoFormatCollection 개체가 IList 인터페이스로 캐스팅된 경우 지정된 인덱스에 있는 요소를 가져옵니다.

IList.Remove(Object)

DesignerAutoFormatCollection 개체가 IList 인터페이스로 캐스팅된 경우 컬렉션에서 처음 나타나는 특정 개체를 제거합니다.

IList.RemoveAt(Int32)

DesignerAutoFormatCollection 개체가 IList 인터페이스로 캐스팅된 경우 지정된 인덱스에서 항목을 제거합니다.

확장 메서드

Cast<TResult>(IEnumerable)

IEnumerable의 요소를 지정된 형식으로 캐스팅합니다.

OfType<TResult>(IEnumerable)

지정된 형식에 따라 IEnumerable의 요소를 필터링합니다.

AsParallel(IEnumerable)

쿼리를 병렬화할 수 있도록 합니다.

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상

추가 정보