IComponentDiscoveryService.GetComponentTypes メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > IComponentDiscoveryService.GetComponentTypes メソッドの意味・解説 

IComponentDiscoveryService.GetComponentTypes メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

使用できるコンポーネント型のリスト取得します

名前空間: System.ComponentModel.Design
アセンブリ: System (system.dll 内)
構文構文

Function GetComponentTypes ( _
    designerHost As IDesignerHost, _
    baseType As Type _
) As ICollection
Dim instance As IComponentDiscoveryService
Dim designerHost As IDesignerHost
Dim baseType As Type
Dim returnValue As ICollection

returnValue = instance.GetComponentTypes(designerHost, baseType)
ICollection GetComponentTypes (
    IDesignerHost designerHost,
    Type baseType
)
ICollection^ GetComponentTypes (
    IDesignerHost^ designerHost, 
    Type^ baseType
)
ICollection GetComponentTypes (
    IDesignerHost designerHost, 
    Type baseType
)
function GetComponentTypes (
    designerHost : IDesignerHost, 
    baseType : Type
) : ICollection

パラメータ

designerHost

デザインサービス提供するデザイナ ホストnull 参照 (Visual Basic では Nothing) でもかまいません

baseType

取得するコンポーネント指定する基本型null 参照 (Visual Basic では Nothing) でもかまいません

戻り値
使用できるコンポーネント型のリスト

解説解説

GetComponentTypes メソッドは、使用できるコンポーネント型 (IComponent インターフェイス実装する型) のリスト取得しますbaseType パラメータnull 参照 (Visual Basic では Nothing) の場合すべてのコンポーネント取得されます。それ以外場合は、baseType から派生したコンポーネント型のみが返されます。

designerHost パラメータの値を渡すと、型解決スコープdesignerHost設定します。つまり、型がグローバル アセンブリ キャッシュではなくディスク上にある ToolboxItem が存在する場合、その型は designerHost介した読み込みを行うことができません。

designerHost に対して null 参照 (Visual Basic では Nothing) を渡すと、グローバル アセンブリ キャッシュまたは System.Reflection.Assembly.LoadFrom メソッドから問い合わせができるすべての型が返されます。

使用例使用例

GetComponentTypes メソッド使用して、ScrollableControl 型から派生したすべての型を検索する方法次のコード例示します

' This class defines the smart tags that appear on the control
' that is being designed.

Friend Class DemoActionList
    Inherits System.ComponentModel.Design.DesignerActionList
    ' Cache a reference to the designer host.
    Private host As IDesignerHost = Nothing

    ' Cache a reference to the control.
    Private relatedControl As DemoControl =
 Nothing

    ' Cache a reference to the designer.
    Private relatedDesigner As DemoControlDesigner
 = Nothing

    'The constructor associates the control 
    'with the smart tag list.
    Public Sub New(ByVal
 component As IComponent)
        MyBase.New(component)
        Me.relatedControl = component '

        Me.host = Me.Component.Site.GetService(GetType(IDesignerHost))

        Dim dcd As IDesigner = host.GetDesigner(Me.Component)
        Me.relatedDesigner = dcd

    End Sub

    ' This method creates and populates the 
    ' DesignerActionItemCollection which is used to 
    ' display smart tag items.
    Public Overrides Function
 GetSortedActionItems() As DesignerActionItemCollection
        Dim items As New
 DesignerActionItemCollection()

        ' If the Timer component has not been created, show the
        ' "Create Timer" DesignerAction item.
        '
        ' If the Timer component exists, show the timer-related
        ' options.
        If Me.relatedDesigner.createdTimer
 Is Nothing Then
            items.Add(New DesignerActionMethodItem(Me,
 "CreateTimer", "Create Timer",
 True))
        Else
            items.Add(New DesignerActionMethodItem(Me,
 "ShowEventHandlerCode", "Show
 Event Handler Code", True))

            items.Add(New DesignerActionMethodItem(Me,
 "RemoveTimer", "Remove Timer",
 True))
        End If

        items.Add(New DesignerActionMethodItem(Me,
 "GetExtenderProviders", "Get
 Extender Providers", True))

        items.Add(New DesignerActionMethodItem(Me,
 "GetDemoControlReferences", "Get
 DemoControl References", True))

        items.Add(New DesignerActionMethodItem(Me,
 "GetPathOfAssembly", "Get Path
 of Executing Assembly", True))

        items.Add(New DesignerActionMethodItem(Me,
 "GetComponentTypes", "Get ScrollableControl
 Types", True))

        items.Add(New DesignerActionMethodItem(Me,
 "GetToolboxCategories", "Get
 Toolbox Categories", True))

        items.Add(New DesignerActionMethodItem(Me,
 "SetBackColor", "Set Back Color",
 True))

        Return items
    End Function

    ' This method creates a Timer component using the 
    ' IDesignerHost.CreateComponent method. It also 
    ' creates an event handler for the Timer component's
    ' tick event.
    Private Sub CreateTimer()
        If Not (Me.host
 Is Nothing) Then
            If Me.relatedDesigner.createdTimer
 Is Nothing Then
                ' Create and configure the Timer object.
                Me.relatedDesigner.createdTimer = Me.host.CreateComponent(GetType(Timer))

                Dim t As Timer = Me.relatedDesigner.createdTimer
                t.Interval = 1000
                t.Enabled = True

                Dim eventColl As EventDescriptorCollection
 = TypeDescriptor.GetEvents(t, New Attribute(-1) {})

                If Not (eventColl Is
 Nothing) Then
                    Dim ed As EventDescriptor
 = eventColl("Tick")

                    If Not (ed Is
 Nothing) Then
                        Dim epd As PropertyDescriptor
 = Me.relatedDesigner.eventBindingService.GetEventProperty(ed)

                        epd.SetValue(t, "timer_Tick")
                    End If
                End If

                Me.relatedDesigner.actionUiService.Refresh(Me.relatedControl)
            End If
        End If
    End Sub

    ' This method uses the IEventBindingService.ShowCode
    ' method to start the Code Editor. It places the caret
    ' in the timer_tick method created by the CreateTimer method.
    Private Sub ShowEventHandlerCode()
        Dim t As Timer = Me.relatedDesigner.createdTimer

        If Not (t Is Nothing)
 Then
            Dim eventColl As EventDescriptorCollection
 = TypeDescriptor.GetEvents(t, New Attribute(-1) {})
            If Not (eventColl Is
 Nothing) Then
                Dim ed As EventDescriptor =
 eventColl("Tick")

                If Not (ed Is
 Nothing) Then
                    Me.relatedDesigner.eventBindingService.ShowCode(t,
 ed)
                End If
            End If
        End If
    End Sub

    ' This method uses the IDesignerHost.DestroyComponent method
    ' to remove the Timer component from the design environment.
    Private Sub RemoveTimer()
        If Not (Me.host
 Is Nothing) Then
            If Not (Me.relatedDesigner.createdTimer
 Is Nothing) Then
                Me.host.DestroyComponent(Me.relatedDesigner.createdTimer)

                Me.relatedDesigner.createdTimer = Nothing

                Me.relatedDesigner.actionUiService.Refresh(Me.relatedControl)
            End If
        End If
    End Sub

    ' This method uses IExtenderListService.GetExtenderProviders
    ' to enumerate all the extender providers and display them 
    ' in a MessageBox.
    Private Sub GetExtenderProviders()
        If Not (Me.relatedDesigner.listService
 Is Nothing) Then
            Dim sb As New
 StringBuilder()

            Dim providers As IExtenderProvider()
 = Me.relatedDesigner.listService.GetExtenderProviders()

            Dim i As Integer
            For i = 0 To providers.Length -
 1
                Dim o As Object
 = providers(i)
                sb.Append(o.ToString())
                sb.Append(ControlChars.Cr + ControlChars.Lf)
            Next i

            MessageBox.Show(sb.ToString(), "Extender Providers")
        End If
    End Sub

    ' This method uses the IReferenceService.GetReferences method
    ' to enumerate all the instances of DemoControl on the 
    ' design surface.
    Private Sub GetDemoControlReferences()
        If Not (Me.relatedDesigner.referenceService
 Is Nothing) Then
            Dim sb As New
 StringBuilder()

            Dim refs As Object()
 = Me.relatedDesigner.referenceService.GetReferences(GetType(DemoControl))

            Dim i As Integer
            For i = 0 To refs.Length - 1
                sb.Append(refs(i).ToString())
                sb.Append(ControlChars.Cr + ControlChars.Lf)
            Next i

            MessageBox.Show(sb.ToString(), "DemoControl References")
        End If
    End Sub

    ' This method uses the ITypeResolutionService.GetPathOfAssembly
    ' method to display the path of the executing assembly.
    Private Sub GetPathOfAssembly()
        If Not (Me.relatedDesigner.typeResService
 Is Nothing) Then
            Dim name As System.Reflection.AssemblyName
 = System.Reflection.Assembly.GetExecutingAssembly().GetName()

            MessageBox.Show(Me.relatedDesigner.typeResService.GetPathOfAssembly(name),
 "Path of executing assembly")
        End If
    End Sub


    ' This method uses the IComponentDiscoveryService.GetComponentTypes
 
    ' method to find all the types that derive from 
    ' ScrollableControl.
    Private Sub GetComponentTypes()
        If Not (Me.relatedDesigner.componentDiscoveryService
 Is Nothing) Then
            Dim components As ICollection =
 Me.relatedDesigner.componentDiscoveryService.GetComponentTypes(host,
 GetType(ScrollableControl))

            If Not (components Is
 Nothing) Then
                If components.Count > 0 Then
                    Dim sb As New
 StringBuilder()

                    Dim e As IEnumerator =
 components.GetEnumerator()

                    While e.MoveNext()
                        sb.Append(e.Current.ToString())
                        sb.Append(ControlChars.Cr + ControlChars.Lf)
                    End While

                    MessageBox.Show(sb.ToString(), "Controls derived
 from ScrollableControl")
                End If
            End If
        End If
    End Sub


    ' This method uses the IToolboxService.CategoryNames
    ' method to enumerate all the categories that appear
    ' in the Toolbox.
    Private Sub GetToolboxCategories()
        If Not (Me.relatedDesigner.toolboxService
 Is Nothing) Then
            Dim sb As New
 StringBuilder()

            Dim names As CategoryNameCollection
 = Me.relatedDesigner.toolboxService.CategoryNames

            Dim name As String
            For Each name In
 names
                sb.Append(name.ToString())
                sb.Append(ControlChars.Cr + ControlChars.Lf)
            Next name

            MessageBox.Show(sb.ToString(), "Toolbox Categories")
        End If
    End Sub


    ' This method sets the shadowed BackColor property on the 
    ' designer. This is the value that is serialized by the 
    ' design environment.
    Private Sub SetBackColor()
        Dim d As New ColorDialog()
        If d.ShowDialog() = DialogResult.OK Then
            Me.relatedDesigner.BackColor = d.Color
        End If
    End Sub
End Class
// This class defines the smart tags that appear on the control
// that is being designed.
internal class DemoActionList :
      System.ComponentModel.Design.DesignerActionList
{
    // Cache a reference to the designer host.
    private IDesignerHost host = null;

    // Cache a reference to the control.
    private DemoControl relatedControl = null;

    // Cache a reference to the designer.
    private DemoControlDesigner relatedDesigner = null;

    //The constructor associates the control 
    //with the smart tag list.
    public DemoActionList(IComponent component)
        : base(component)
    {
        this.relatedControl = component as DemoControl;

        this.host =
            this.Component.Site.GetService(typeof(IDesignerHost))
            as IDesignerHost;

        IDesigner dcd = host.GetDesigner(this.Component);
        this.relatedDesigner = dcd as DemoControlDesigner;
    }

    // This method creates and populates the 
    // DesignerActionItemCollection which is used to 
    // display smart tag items.
    public override DesignerActionItemCollection GetSortedActionItems()
    {
        DesignerActionItemCollection items =
            new DesignerActionItemCollection();

        // If the Timer component has not been created, show the
        // "Create Timer" DesignerAction item.
        //
        // If the Timer component exists, show the timer-related
        // options.

        if (this.relatedDesigner.createdTimer
 == null)
        {
            items.Add(new DesignerActionMethodItem(
                this,
                "CreateTimer",
                "Create Timer",
                true));
        }
        else
        {   
            items.Add(new DesignerActionMethodItem(
                this,
                "ShowEventHandlerCode",
                "Show Event Handler Code",
                true));

            items.Add(new DesignerActionMethodItem(
                this,
                "RemoveTimer",
                "Remove Timer",
                true));
        }

        items.Add(new DesignerActionMethodItem(
           this,
           "GetExtenderProviders",
           "Get Extender Providers",
           true));

        items.Add(new DesignerActionMethodItem(
          this,
          "GetDemoControlReferences",
          "Get DemoControl References",
          true));

        items.Add(new DesignerActionMethodItem(
          this,
          "GetPathOfAssembly",
          "Get Path of Executing Assembly",
          true));

        items.Add(new DesignerActionMethodItem(
          this,
          "GetComponentTypes",
          "Get ScrollableControl Types",
          true));

        items.Add(new DesignerActionMethodItem(
            this,
            "GetToolboxCategories",
            "Get Toolbox Categories",
            true));

        items.Add(new DesignerActionMethodItem(
            this,
            "SetBackColor",
            "Set Back Color",
            true));

        return items;
    }

    // This method creates a Timer component using the 
    // IDesignerHost.CreateComponent method. It also 
    // creates an event handler for the Timer component's
    // tick event.
    private void CreateTimer()
    {
        if (this.host != null)
        {
            if (this.relatedDesigner.createdTimer
 == null)
            {
                // Create and configure the Timer object.
                this.relatedDesigner.createdTimer =
                    this.host.CreateComponent(typeof(Timer)) as
 Timer;
                Timer t = this.relatedDesigner.createdTimer;
                t.Interval = 1000;
                t.Enabled = true;

                EventDescriptorCollection eventColl =
                    TypeDescriptor.GetEvents(t, new Attribute[0]);

                if (eventColl != null)
                {
                    EventDescriptor ed =
                        eventColl["Tick"] as EventDescriptor;
                    if (ed != null)
                    {
                        PropertyDescriptor epd =
                            this.relatedDesigner.eventBindingService.GetEventProperty(ed);

                        epd.SetValue(t, "timer_Tick");
                    }
                }

                this.relatedDesigner.actionUiService.Refresh(this.relatedControl);
            }
        }
    }

    // This method uses the IEventBindingService.ShowCode
    // method to start the Code Editor. It places the caret
    // in the timer_tick method created by the CreateTimer method.
    private void ShowEventHandlerCode()
    {
        Timer t = this.relatedDesigner.createdTimer;

        if (t != null)
        {
            EventDescriptorCollection eventColl =
                TypeDescriptor.GetEvents(t, new Attribute[0]);
            if (eventColl != null)
            {
                EventDescriptor ed =
                    eventColl["Tick"] as EventDescriptor;
                if (ed != null)
                {
                    this.relatedDesigner.eventBindingService.ShowCode(t,
 ed);
                }
            }
        }
    }

    // This method uses the IDesignerHost.DestroyComponent method
    // to remove the Timer component from the design environment.
    private void RemoveTimer()
    {
        if (this.host != null)
        {
            if (this.relatedDesigner.createdTimer
 != null)
            {
                this.host.DestroyComponent(
                    this.relatedDesigner.createdTimer);

                this.relatedDesigner.createdTimer = null;

                this.relatedDesigner.actionUiService.Refresh(
                    this.relatedControl);
            }
        }
    }

    // This method uses IExtenderListService.GetExtenderProviders
    // to enumerate all the extender providers and display them 
    // in a MessageBox.
    private void GetExtenderProviders()
    {
        if (this.relatedDesigner.listService
 != null)
        {
            StringBuilder sb = new StringBuilder();

            IExtenderProvider[] providers =
                this.relatedDesigner.listService.GetExtenderProviders();

            for (int i = 0; i < providers.Length;
 i++)
            {
                sb.Append(providers[i].ToString());
                sb.Append("\r\n");
            }

            MessageBox.Show(
                sb.ToString(), 
                "Extender Providers");
        }
    }

    // This method uses the IReferenceService.GetReferences method
    // to enumerate all the instances of DemoControl on the 
    // design surface.
    private void GetDemoControlReferences()
    {
        if (this.relatedDesigner.referenceService
 != null)
        {
            StringBuilder sb = new StringBuilder();

            object[] refs = this.relatedDesigner.referenceService.GetReferences(typeof(DemoControl));

            for (int i = 0; i < refs.Length;
 i++)
            {
                sb.Append(refs[i].ToString());
                sb.Append("\r\n");
            }

            MessageBox.Show(
                sb.ToString(), 
                "DemoControl References");
        }
    }


    // This method uses the ITypeResolutionService.GetPathOfAssembly
    // method to display the path of the executing assembly.
    private void GetPathOfAssembly()
    {
        if (this.relatedDesigner.typeResService
 != null)
        {
            System.Reflection.AssemblyName name =
                System.Reflection.Assembly.GetExecutingAssembly().GetName();

            MessageBox.Show(
                this.relatedDesigner.typeResService.GetPathOfAssembly(name)
,
                "Path of executing assembly");
        }
    }

    // This method uses the IComponentDiscoveryService.GetComponentTypes
 
    // method to find all the types that derive from 
    // ScrollableControl.
    private void GetComponentTypes()
    {
        if (this.relatedDesigner.componentDiscoveryService
 != null)
        {
            ICollection components = this.relatedDesigner.componentDiscoveryService.GetComponentTypes(host,
 typeof(ScrollableControl));

            if (components != null)
            {
                if (components.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();

                    IEnumerator e = components.GetEnumerator();

                    while (e.MoveNext())
                    {
                        sb.Append(e.Current.ToString());
                        sb.Append("\r\n");

                    }

                    MessageBox.Show(
                        sb.ToString(), 
                        "Controls derived from ScrollableControl");
                }
            }
        }
    }

    // This method uses the IToolboxService.CategoryNames
    // method to enumerate all the categories that appear
    // in the Toolbox.
    private void GetToolboxCategories()
    {
        if (this.relatedDesigner.toolboxService
 != null)
        {
            StringBuilder sb = new StringBuilder();

            CategoryNameCollection names = this.relatedDesigner.toolboxService.CategoryNames;

            foreach (string name in
 names)
            {
                sb.Append(name.ToString());
                sb.Append("\r\n");
            }

            MessageBox.Show(sb.ToString(), "Toolbox Categories");
        }
    }

    // This method sets the shadowed BackColor property on the 
    // designer. This is the value that is serialized by the 
    // design environment.
    private void SetBackColor()
    {
        ColorDialog d = new ColorDialog();
        if (d.ShowDialog() == DialogResult.OK)
        {
            this.relatedDesigner.BackColor = d.Color;
        }
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
IComponentDiscoveryService インターフェイス
IComponentDiscoveryService メンバ
System.ComponentModel.Design 名前空間
IDesignerHost
IComponent インターフェイス



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「IComponentDiscoveryService.GetComponentTypes メソッド」の関連用語

IComponentDiscoveryService.GetComponentTypes メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



IComponentDiscoveryService.GetComponentTypes メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS