TemplateGroupCollection TemplateGroupCollection TemplateGroupCollection TemplateGroupCollection Class

定義

表示控制項設計工具內的 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
繼承
TemplateGroupCollectionTemplateGroupCollectionTemplateGroupCollectionTemplateGroupCollection
實作

範例

下列程式碼範例示範如何定義簡單的控制項設計工具衍生自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
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

備註

ControlDesigner類別,且任何衍生的類別,定義TemplateGroups屬性設為TemplateGroupCollection物件。The ControlDesigner class, and any derived class, defines the TemplateGroups property as a TemplateGroupCollection object. TemplateGroupCollection屬性通常僅供設計主應用程式這類Visual Studio 2005Visual Studio 2005The 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:

  • Add方法,將單一的群組加入至集合。The Add method to add a single group to the collection.

  • Insert方法,將群組加入集合中的特定索引處。The 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.

  • IndexOf方法來擷取集合中群組的索引。The 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.

  • AddRange方法,將多個群組加入至集合。The 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() TemplateGroupCollection() TemplateGroupCollection()

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

屬性

Count Count Count Count

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

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

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

方法

Add(TemplateGroup) Add(TemplateGroup) Add(TemplateGroup) Add(TemplateGroup)

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

AddRange(TemplateGroupCollection) AddRange(TemplateGroupCollection) AddRange(TemplateGroupCollection) AddRange(TemplateGroupCollection)

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

Clear() Clear() Clear() Clear()

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

Contains(TemplateGroup) Contains(TemplateGroup) Contains(TemplateGroup) Contains(TemplateGroup)

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

CopyTo(TemplateGroup[], Int32) CopyTo(TemplateGroup[], Int32) CopyTo(TemplateGroup[], Int32) 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) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Object)
GetType() GetType() GetType() GetType()

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

(Inherited from Object)
IndexOf(TemplateGroup) IndexOf(TemplateGroup) IndexOf(TemplateGroup) IndexOf(TemplateGroup)

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

Insert(Int32, TemplateGroup) Insert(Int32, TemplateGroup) Insert(Int32, TemplateGroup) Insert(Int32, TemplateGroup)

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

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
Remove(TemplateGroup) Remove(TemplateGroup) Remove(TemplateGroup) Remove(TemplateGroup)

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

RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

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

ToString() ToString() ToString() ToString()

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

(Inherited from Object)

明確介面實作

ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32)

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

ICollection.Count ICollection.Count ICollection.Count ICollection.Count

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

ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized

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

ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot

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

IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

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

IList.Add(Object) IList.Add(Object) IList.Add(Object) IList.Add(Object)

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

IList.Clear() IList.Clear() IList.Clear() IList.Clear()

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

IList.Contains(Object) IList.Contains(Object) IList.Contains(Object) IList.Contains(Object)

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

IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object)

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

IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object)

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

IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize

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

IList.IsReadOnly IList.IsReadOnly IList.IsReadOnly IList.IsReadOnly

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

IList.Item[Int32] IList.Item[Int32] IList.Item[Int32] IList.Item[Int32]

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

IList.Remove(Object) IList.Remove(Object) IList.Remove(Object) IList.Remove(Object)

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

IList.RemoveAt(Int32) IList.RemoveAt(Int32) IList.RemoveAt(Int32) IList.RemoveAt(Int32)

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

Extension Methods

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

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

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

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

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

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

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

將轉換IEnumerableIQueryableConverts an IEnumerable to an IQueryable.

適用於

另請參閱