TemplateGroupCollection 類別

定義

表示控制項設計工具內的 TemplateGroup 物件集合。Represents a collection of TemplateGroup objects within a control designer. 這個類別無法被繼承。This class cannot be inherited.

public ref class TemplateGroupCollection sealed : System::Collections::IList
public sealed class TemplateGroupCollection : System.Collections.IList
type TemplateGroupCollection = class
    interface IList
    interface ICollection
    interface IEnumerable
Public NotInheritable Class TemplateGroupCollection
Implements IList
繼承
TemplateGroupCollection
實作

範例

下列程式碼範例示範如何定義衍生自ControlDesigner類別的簡單控制項設計工具。The following code example demonstrates how to define a simple control designer that is derived from the ControlDesigner class. 衍生的控制項設計工具會TemplateGroups藉由取得針對基類定義的範本群組, 並加入衍生控制項設計工具特有的範本群組, 來實作為屬性。The derived control designer implements the TemplateGroups property by getting the template groups that are defined for the base class and adding a template group that is specific to the derived control designer.

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

namespace Examples.AspNet
{
    // Define a simple control designer that adds a
    // template group to the template group collection.
    class DerivedControlDesigner : System.Web.UI.Design.ControlDesigner
    {
        private DerivedControl internalControl = null;

        private const String templateGroupName = "My template group";
        private const String templateDefinitionName1 = "First";
        private const String templateDefinitionName2 = "Second";
        private TemplateGroup internalGroup = null;

        // Override the read-only TemplateGroups property.
        // Get the base group collection, and add a group 
        // with two template definitions for the derived
        // control designer.
        public override TemplateGroupCollection TemplateGroups
        {
            get
            {
                // Start with the groups defined by the base designer class.
                TemplateGroupCollection groups = base.TemplateGroups;

                if (internalGroup == null) 
                {
                    // Define a new group with two template definitions.
                    internalGroup = new TemplateGroup(templateGroupName, 
                                                internalControl.ControlStyle);

                    TemplateDefinition templateDef1 = new TemplateDefinition(this, 
                        templateDefinitionName1, internalControl, 
                        templateDefinitionName1, internalControl.ControlStyle);

                    TemplateDefinition templateDef2 = new TemplateDefinition(this, 
                        templateDefinitionName2, internalControl, 
                        templateDefinitionName2, internalControl.ControlStyle);

                    internalGroup.AddTemplateDefinition(templateDef1);
                    internalGroup.AddTemplateDefinition(templateDef2);
                }


                // Add the new template group to the collection.
                groups.Add(internalGroup);

                return groups;
            }
        }

    }

    // Define a simple web control, and associate it with the designer.
    [DesignerAttribute(typeof(DerivedControlDesigner),
                       typeof(IDesigner))]
    public class DerivedControl : WebControl
    {
        // Define derived control behavior here.
    }

}
Imports System.Web.UI
Imports System.Web.UI.Design
Imports System.Web.UI.WebControls
Imports System.Web.UI.Design.WebControls
Imports System.ComponentModel
Imports System.ComponentModel.Design

Namespace Examples.AspNet

    ' Define a simple control designer that adds a
    ' template group to the template group collection.
    Class DerivedControlDesigner
        Inherits System.Web.UI.Design.ControlDesigner

        Private Dim internalControl As DerivedControl = Nothing
    
        Private Const templateGroupName As String = "My template group"
        Private Const templateDefinitionName1 As String = "First"
        Private Const templateDefinitionName2 As String = "Second"
        Private Dim internalGroup As TemplateGroup = Nothing

        ' Override the read-only TemplateGroups property.
        ' Get the base group collection, and add a group 
        ' with two template definitions for the derived
        ' control designer.
        Public Overrides ReadOnly Property TemplateGroups As TemplateGroupCollection
            Get

                ' Start with the groups defined by the base designer class.
                Dim groups As TemplateGroupCollection  = MyBase.TemplateGroups

                If internalGroup Is Nothing

                    ' Define a new group with two template definitions.
                    internalGroup = New TemplateGroup(templateGroupName, _
                                                internalControl.ControlStyle)

                    Dim templateDef1 As TemplateDefinition = new TemplateDefinition(Me, _
                        templateDefinitionName1, internalControl, _
                        templateDefinitionName1, internalControl.ControlStyle)

                    Dim templateDef2 As TemplateDefinition = new TemplateDefinition(Me, _
                        templateDefinitionName2, internalControl, _
                        templateDefinitionName2, internalControl.ControlStyle)

                    internalGroup.AddTemplateDefinition(templateDef1)
                    internalGroup.AddTemplateDefinition(templateDef2)

                End If

                ' Add the new template group to the collection.
                groups.Add(internalGroup)

                return groups
            End Get
        End Property

    End Class

    ' Simple Web control, derived from the Web control class.
    <DesignerAttribute(GetType(DerivedControlDesigner), GetType(IDesigner))> _
    Public Class DerivedControl
        Inherits WebControl
        
        ' Define derived control behavior here.
    End Class

End Namespace

備註

類別和任何衍生類別都會將TemplateGroups屬性定義為TemplateGroupCollection物件。 ControlDesignerThe ControlDesigner class, and any derived class, defines the TemplateGroups property as a TemplateGroupCollection object. 屬性通常僅供設計主機 (例如) Visual Studio 2005Visual Studio 2005使用。 TemplateGroupCollectionThe TemplateGroupCollection property is typically used only by a design host such as Visual Studio 2005Visual Studio 2005.

隨著物件的加入, 集合會動態增加大小。The collection dynamically increases in size as objects are added. 這個集合中的索引是以零為基底。Indexes in this collection are zero-based. Count使用屬性, 判斷集合中有多少個群組。Use the Count property to determine how many groups are in the collection.

此外, 請使用TemplateGroupCollection方法和屬性來提供下列功能:Additionally, use the TemplateGroupCollection methods and properties to provide the following functionality:

  • 要將單一群組新增至集合的方法。AddThe Add method to add a single group to the collection.

  • 要在集合中的特定索引處新增群組的方法。InsertThe Insert method to add a group at a particular index within the collection.

  • Remove移除群組的方法。The Remove method to remove a group.

  • RemoveAt在特定索引中移除群組的方法。The RemoveAt method to remove the group at a particular index.

  • 判斷Contains特定群組是否已存在於集合中的方法。The Contains method to determine whether a particular group is already in the collection.

  • 要在集合中取得群組索引的方法。IndexOfThe IndexOf method to retrieve the index of a group within the collection.

  • 用來取得或設定特定索引之群組的索引子(使用陣列標記法)。Item[Int32]The Item[Int32] indexer to get or set the group at a particular index, using array notation.

  • 將多個群組新增至集合的方法。AddRangeThe AddRange method to add multiple groups to the collection.

    您可以將多個群組新增為群組陣列, 或TemplateGroupCollection當做您透過另一個控制項設計工具的TemplateGroups屬性取得的物件。You can add multiple groups either as an array of groups or as a TemplateGroupCollection object that you retrieve through the TemplateGroups property of another control designer.

  • Clear從集合中移除所有群組的方法。The Clear method to remove all groups from the collection.

建構函式

TemplateGroupCollection()

初始化 TemplateGroupCollection 類別的新執行個體。Initializes a new instance of the TemplateGroupCollection class.

屬性

Count

取得集合中 TemplateGroup 物件的數目。Gets the number of TemplateGroup objects in the collection.

Item[Int32]

取得或設定位於集合中指定索引上的 TemplateGroup 物件。Gets or sets a TemplateGroup object at the specified index in the collection.

方法

Add(TemplateGroup)

將指定的 TemplateGroup 物件加入至集合的尾端。Adds the specified TemplateGroup object to the end of the collection.

AddRange(TemplateGroupCollection)

將現有 TemplateGroupCollection 物件中的樣板群組加入至目前的 TemplateGroupCollection 物件。Adds the template groups in an existing TemplateGroupCollection object to the current TemplateGroupCollection object.

Clear()

移除集合中所有的群組。Removes all groups from the collection.

Contains(TemplateGroup)

判斷集合中是否包含指定的群組。Determines whether the specified group is contained within the collection.

CopyTo(TemplateGroup[], Int32)

將集合中的群組複製到相容的一維陣列,從目標陣列的指定索引處開始。Copies the groups in the collection to a compatible one-dimensional array, starting at the specified index of the target array.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
IndexOf(TemplateGroup)

傳回指定的 TemplateGroup 物件在集合中的索引。Returns the index of the specified TemplateGroup object within the collection.

Insert(Int32, TemplateGroup)

TemplateGroup 插入位於指定索引的集合。Inserts a TemplateGroup object into the collection at the specified index.

MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
Remove(TemplateGroup)

從集合中移除指定的 TemplateGroup 物件。Removes the specified TemplateGroup object from the collection.

RemoveAt(Int32)

移除位於集合中指定索引上的 TemplateGroup 物件。Removes the TemplateGroup object at the specified index within the collection.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

明確介面實作

ICollection.CopyTo(Array, Int32)

如需這個成員的說明,請參閱 CopyTo(Array, Int32)For a description of this member, see CopyTo(Array, Int32).

ICollection.Count

如需這個成員的說明,請參閱 CountFor a description of this member, see Count.

ICollection.IsSynchronized

如需這個成員的說明,請參閱 IsSynchronizedFor a description of this member, see IsSynchronized.

ICollection.SyncRoot

如需這個成員的說明,請參閱 SyncRootFor a description of this member, see SyncRoot.

IEnumerable.GetEnumerator()

如需這個成員的說明,請參閱 GetEnumerator()For a description of this member, see GetEnumerator().

IList.Add(Object)

如需這個成員的說明,請參閱 Add(Object)For a description of this member, see Add(Object).

IList.Clear()

如需這個成員的說明,請參閱 Clear()For a description of this member, see Clear().

IList.Contains(Object)

如需這個成員的說明,請參閱 Contains(Object)For a description of this member, see Contains(Object).

IList.IndexOf(Object)

如需這個成員的說明,請參閱 IndexOf(Object)For a description of this member, see IndexOf(Object).

IList.Insert(Int32, Object)

如需這個成員的說明,請參閱 Insert(Int32, Object)For a description of this member, see Insert(Int32, Object).

IList.IsFixedSize

如需這個成員的說明,請參閱 IsFixedSizeFor a description of this member, see IsFixedSize.

IList.IsReadOnly

如需這個成員的說明,請參閱 IsReadOnlyFor a description of this member, see IsReadOnly.

IList.Item[Int32]

如需這個成員的說明,請參閱 IList 類別。For a description of this member, see the IList class.

IList.Remove(Object)

如需這個成員的說明,請參閱 Remove(Object)For a description of this member, see Remove(Object).

IList.RemoveAt(Int32)

如需這個成員的說明,請參閱 RemoveAt(Int32)For a description of this member, see RemoveAt(Int32).

擴充方法

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

啟用查詢的平行化作業。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryableConverts an IEnumerable to an IQueryable.

適用於

另請參閱