CategoryNameCollection 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表類別名稱字串的集合。
public ref class CategoryNameCollection sealed : System::Collections::ReadOnlyCollectionBase
public sealed class CategoryNameCollection : System.Collections.ReadOnlyCollectionBase
type CategoryNameCollection = class
inherit ReadOnlyCollectionBase
Public NotInheritable Class CategoryNameCollection
Inherits ReadOnlyCollectionBase
- 繼承
範例
下列程式代碼範例會嘗試擷取控件在設計模式中網站時擷取 IToolboxService 。 IToolboxService如果擷取 ,程式代碼會取得每個工具箱類別的名稱,並在控件的介面上繪製每個名稱。
#using <System.Windows.Forms.dll>
#using <System.Data.dll>
#using <System.Drawing.dll>
#using <System.dll>
using namespace System;
using namespace System::Collections;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::Drawing;
using namespace System::Drawing::Design;
using namespace System::Data;
using namespace System::Windows::Forms;
namespace ToolboxCategoryNamesControl
{
public ref class ToolboxCategoryNamesControl: public System::Windows::Forms::UserControl
{
private:
System::Drawing::Design::IToolboxService^ toolboxService;
System::Drawing::Design::CategoryNameCollection^ categoryNames;
public:
ToolboxCategoryNamesControl()
{
this->BackColor = System::Drawing::Color::Beige;
this->Name = "Category Names Display Control";
this->Size = System::Drawing::Size( 264, 200 );
}
property System::ComponentModel::ISite^ Site
{
// Obtain or reset IToolboxService^ reference on each siting of control.
virtual System::ComponentModel::ISite^ get() override
{
return __super::Site;
}
virtual void set( System::ComponentModel::ISite^ value ) override
{
__super::Site = value;
// If the component was sited, attempt to obtain
// an IToolboxService^ instance.
if ( __super::Site != nullptr )
{
toolboxService = dynamic_cast<IToolboxService^>(this->GetService( IToolboxService::typeid ));
// If an IToolboxService* was located, update the category list.
if ( toolboxService != nullptr )
categoryNames = toolboxService->CategoryNames;
}
else
toolboxService = nullptr;
}
}
protected:
[System::Security::Permissions::PermissionSetAttribute(System::Security::Permissions::SecurityAction::Demand, Name="FullTrust")]
virtual void OnPaint( System::Windows::Forms::PaintEventArgs^ e ) override
{
if ( categoryNames != nullptr )
{
e->Graphics->DrawString( "IToolboxService category names list:", gcnew System::Drawing::Font( "Arial",9 ), Brushes::Black, 10, 10 );
// categoryNames is a CategoryNameCollection obtained from
// the IToolboxService*. CategoryNameCollection is a read-only
// String* collection.
// Output each category name in the CategoryNameCollection.
for ( int i = 0; i < categoryNames->Count; i++ )
e->Graphics->DrawString( categoryNames[ i ], gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, (float)10, (float)24 + (10 * i) );
}
}
};
}
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.Data;
using System.Windows.Forms;
namespace ToolboxCategoryNamesControl
{
public class ToolboxCategoryNamesControl : System.Windows.Forms.UserControl
{
private System.Drawing.Design.IToolboxService toolboxService;
private System.Drawing.Design.CategoryNameCollection categoryNames;
public ToolboxCategoryNamesControl()
{
this.BackColor = System.Drawing.Color.Beige;
this.Name = "Category Names Display Control";
this.Size = new System.Drawing.Size(264, 200);
}
// Obtain or reset IToolboxService reference on each siting of control.
public override System.ComponentModel.ISite Site
{
get
{
return base.Site;
}
set
{
base.Site = value;
// If the component was sited, attempt to obtain
// an IToolboxService instance.
if( base.Site != null )
{
toolboxService = (IToolboxService)this.GetService(typeof(IToolboxService));
// If an IToolboxService was located, update the category list.
if( toolboxService != null )
categoryNames = toolboxService.CategoryNames;
}
else
{
toolboxService = null;
}
}
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
if( categoryNames != null )
{
e.Graphics.DrawString("IToolboxService category names list:", new Font("Arial", 9), Brushes.Black, 10, 10);
// categoryNames is a CategoryNameCollection obtained from
// the IToolboxService. CategoryNameCollection is a read-only
// string collection.
// Output each category name in the CategoryNameCollection.
for( int i=0; i< categoryNames.Count; i++ )
e.Graphics.DrawString(categoryNames[i], new Font("Arial", 8), Brushes.Black, 10, 24+(10*i));
}
}
}
}
Imports System.Collections
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Drawing.Design
Imports System.Data
Imports System.Windows.Forms
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Public Class ToolboxCategoryNamesControl
Inherits System.Windows.Forms.UserControl
Private toolboxService As System.Drawing.Design.IToolboxService
Private categoryNames As System.Drawing.Design.CategoryNameCollection
Public Sub New()
Me.BackColor = System.Drawing.Color.Beige
Me.Name = "Category Names Display Control"
Me.Size = New System.Drawing.Size(264, 200)
End Sub
' Obtain or reset IToolboxService reference on each siting of control.
Public Overrides Property Site() As System.ComponentModel.ISite
Get
Return MyBase.Site
End Get
Set(ByVal Value As System.ComponentModel.ISite)
MyBase.Site = Value
' If the component was sited, attempt to obtain
' an IToolboxService instance.
If (MyBase.Site IsNot Nothing) Then
toolboxService = CType(Me.GetService(GetType(IToolboxService)), IToolboxService)
' If an IToolboxService was located, update the category list.
If (toolboxService IsNot Nothing) Then
categoryNames = toolboxService.CategoryNames
End If
Else
toolboxService = Nothing
End If
End Set
End Property
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
If (categoryNames IsNot Nothing) Then
e.Graphics.DrawString("IToolboxService category names list:", New Font("Arial", 9), Brushes.Black, 10, 10)
' categoryNames is a CategoryNameCollection obtained from
' the IToolboxService. CategoryNameCollection is a read-only
' string collection.
' Output each category name in the CategoryNameCollection.
Dim i As Integer
For i = 0 To categoryNames.Count - 1
e.Graphics.DrawString(categoryNames(i), New Font("Arial", 8), Brushes.Black, 10, 24 + 10 * i)
Next i
End If
End Sub
End Class
備註
這個集合是用來儲存工具箱類別名稱的集合。
建構函式
CategoryNameCollection(CategoryNameCollection) |
使用指定的集合,初始化 CategoryNameCollection 類別的新執行個體。 |
CategoryNameCollection(String[]) |
使用指定的名稱陣列,初始化 CategoryNameCollection 類別的新執行個體。 |
屬性
Count |
取得 ReadOnlyCollectionBase 執行個體中包含的元素數目。 (繼承來源 ReadOnlyCollectionBase) |
InnerList |
取得包含於 ReadOnlyCollectionBase 執行個體中的項目清單。 (繼承來源 ReadOnlyCollectionBase) |
Item[Int32] |
取得在指定索引處的分類名稱。 |
方法
Contains(String) |
指示指定的分類是否包含在集合中。 |
CopyTo(String[], Int32) |
將集合元素複製到指定索引處的指定陣列。 |
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetEnumerator() |
傳回可逐一查看 ReadOnlyCollectionBase 執行個體的列舉值。 (繼承來源 ReadOnlyCollectionBase) |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
IndexOf(String) |
取得指定值的索引。 |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |
明確介面實作
ICollection.CopyTo(Array, Int32) |
從目標陣列的指定索引開始,將整個 ReadOnlyCollectionBase 複製到相容的一維 Array。 (繼承來源 ReadOnlyCollectionBase) |
ICollection.IsSynchronized |
取得值,指出對 ReadOnlyCollectionBase 物件的存取是否為同步的 (執行緒安全)。 (繼承來源 ReadOnlyCollectionBase) |
ICollection.SyncRoot |
取得可用來同步存取 ReadOnlyCollectionBase 物件的物件。 (繼承來源 ReadOnlyCollectionBase) |
擴充方法
Cast<TResult>(IEnumerable) |
將 IEnumerable 的項目轉換成指定的型別。 |
OfType<TResult>(IEnumerable) |
根據指定的型別來篩選 IEnumerable 的項目。 |
AsParallel(IEnumerable) |
啟用查詢的平行化作業。 |
AsQueryable(IEnumerable) |
將 IEnumerable 轉換成 IQueryable。 |