次の方法で共有


EventsTab クラス

選択およびリンクのためのイベントを表示できる PropertyTab を提供します。

この型のすべてのメンバの一覧については、EventsTab メンバ を参照してください。

System.Object
   System.Windows.Forms.Design.PropertyTab
      System.Windows.Forms.Design.EventsTab

Public Class EventsTab
   Inherits PropertyTab
[C#]
public class EventsTab : PropertyTab
[C++]
public __gc class EventsTab : public PropertyTab
[JScript]
public class EventsTab extends PropertyTab

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

使用例

[C#, C++] EventsTab のコード例を次に示します。選択すると、 EventsTab には、デリゲート型の順序に従ってコンポーネントのイベントの一覧が表示されます。

 
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace EventsTabExample
{    
    // This component adds a TypeEventsTab to the Properties Window.
    [PropertyTabAttribute(typeof(TypeEventsTab), PropertyTabScope.Document)]
    public class TypeEventsTabComponent : Component
    {
        public TypeEventsTabComponent()
        {
        }
    }

    // This example events tab lists events by their delegate type.
    public class TypeEventsTab : System.Windows.Forms.Design.EventsTab
    {
        [BrowsableAttribute(true)]
        // This string contains a Base-64 encoded and serialized example 
        // property tab image.
        private string img = "AAEAAAD/////AQAAAAAAAAAMAgAAAFRTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj0xLjAuMzMwMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABVTeXN0ZW0uRHJhd2luZy5CaXRtYXABAAAABERhdGEHAgIAAAAJAwAAAA8DAAAAtgIAAAJCTbYCAAAAAAAANgAAACgAAAANAAAAEAAAAAEAGAAAAAAAAAAAAMQOAADEDgAAAAAAAAAAAADO1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tn/ztbZztbZHh4eHh4eztbZztbZztbZztbZztbZztbZztbZztbZztbZ/87W2c7W2QDBAB4eHh4eHs7W2c7W2c7W2c7W2c7W2c7W2c7W2c7W2f/O1tnO1tnO1tkAwQAeHh4eHh7O1tnO1tnO1tnO1tnO1tnO1tnO1tn/ztbZztbZlJSU////AMEAHh4eHh4eztbZztbZztbZztbZztbZztbZ/87W2c7W2c7W2ZSUlP///wDBAB4eHh4eHs7W2c7W2c7W2c7W2c7W2f/O1tnO1tnO1tnO1tmUlJT///8AwQAeHh4eHh7O1tnO1tnO1tnO1tn/ztbZHh4eHh4eHh4eHh4eHh4e////AIAAHh4eHh4eztbZztbZztbZ/87W2ZSUlP///wDBAADBAADBAADBAADBAACAAB4eHh4eHs7W2c7W2f/O1tnO1tmUlJT///8AwQAAgAAeHh4eHh7O1tnO1tnO1tnO1tnO1tn/ztbZztbZztbZlJSU////AMEAAIAAHh4eHh4eztbZztbZztbZztbZ/87W2c7W2c7W2c7W2ZSUlP///wDBAACAAB4eHh4eHs7W2c7W2c7W2f/O1tnO1tnO1tnO1tnO1tmUlJT///8AwQAAgAAeHh4eHh7O1tnO1tn/ztbZztbZztbZztbZztbZztbZlJSU////AMEAAIAAHh4eHh4eztbZ/87W2c7W2c7W2c7W2c7W2c7W2c7W2ZSUlP///wDBAACAAB4eHs7W2f/O1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tn/Cw==";
        private IServiceProvider sp;

        public TypeEventsTab(IServiceProvider sp) : base(sp)
        {
            this.sp = sp;           
        }
                  
        // Returns the properties of the specified component extended with a 
        // CategoryAttribute reflecting the name of the type of the property.
        public override System.ComponentModel.PropertyDescriptorCollection 
            GetProperties(ITypeDescriptorContext context, object component, 
            System.Attribute[] attributes)
        {            
            // Obtain an instance of the IEventBindingService.
            IEventBindingService eventPropertySvc = (IEventBindingService)
                sp.GetService(typeof(IEventBindingService));

            // Return if an IEventBindingService could not be obtained.
            if (eventPropertySvc == null)             
                return new PropertyDescriptorCollection(null);
            
            // Obtain the events on the component.
            EventDescriptorCollection events = 
                TypeDescriptor.GetEvents(component, attributes);       
     
            // Create an array of the events, where each event is assigned 
            // a category matching its type.
            EventDescriptor[] newEvents = new EventDescriptor[events.Count];
            for(int i=0;i < events.Count;i++)             
                newEvents[i] = TypeDescriptor.CreateEvent(events[i].ComponentType, events[i], 
                    new CategoryAttribute(events[i].EventType.FullName));            
            events = new EventDescriptorCollection(newEvents);

            // Return event properties for the event descriptors.
            return eventPropertySvc.GetEventProperties(events);
        }        

        // Provides the name for the event property tab.
        public override string TabName
        {
            get
            {
                return "Events by Type";
            }
        }

        // Provides an image for the event property tab.
        public override System.Drawing.Bitmap Bitmap
        {
            get
            {
                Bitmap bmp = new Bitmap(DeserializeFromBase64Text(img));
                return bmp;
            }
        }

        // This method can be used to retrieve an Image from a block of 
        // Base64-encoded text.
        private Image DeserializeFromBase64Text(string text)
        {
            Image img = null;
            byte[] memBytes = Convert.FromBase64String(text);
            IFormatter formatter = new BinaryFormatter();
            MemoryStream stream = new MemoryStream(memBytes);
            img = (Image)formatter.Deserialize(stream);
            stream.Close();
            return img;
        }
    }
}

[C++] 
#using <mscorlib.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>
#using <System.dll>
using namespace System;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::Collections;
using namespace System::Drawing;
using namespace System::IO;
using namespace System::Reflection;
using namespace System::Runtime::Serialization;
using namespace System::Runtime::Serialization::Formatters::Binary;
using namespace System::Windows::Forms;
using namespace System::Windows::Forms::Design;

public __gc class TypeEventsTab;

// This component adds a TypeEventsTab to the Properties Window.
[PropertyTabAttribute(__typeof(TypeEventsTab), PropertyTabScope::Document)]
public __gc class TypeEventsTabComponent : public Component
{
public:
    TypeEventsTabComponent()
    {
    }
};

// This example events tab lists events by their delegate type.
public __gc class TypeEventsTab : public System::Windows::Forms::Design::EventsTab
{
private:
    [BrowsableAttribute(true)]
    // This string contains a Base-64 encoded and serialized example 
    // property tab image.
    String* img;
    IServiceProvider* sp;

public:
    TypeEventsTab(IServiceProvider* sp) : EventsTab(sp)
    {
        this->sp = sp;           
        String* s = S"AAEAAAD/////AQAAAAAAAAAMAgAAAFRTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj0xLjAuMzMwMC4w"
            S"LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABVTeXN0ZW0uRHJhd2luZy5CaXRt"
            S"YXABAAAABERhdGEHAgIAAAAJAwAAAA8DAAAAtgIAAAJCTbYCAAAAAAAANgAAACgAAAANAAAAEAAAAAEAGAAAAAAAAAAAAMQOAADED"
            S"gAAAAAAAAAAAADO1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tn/ztbZztbZHh4eHh4eztbZztbZztbZztbZztb"
            S"ZztbZztbZztbZztbZ/87W2c7W2QDBAB4eHh4eHs7W2c7W2c7W2c7W2c7W2c7W2c7W2c7W2f/O1tnO1tnO1tkAwQAeHh4eHh7O1tnO1"
            S"tnO1tnO1tnO1tnO1tnO1tn/ztbZztbZlJSU////AMEAHh4eHh4eztbZztbZztbZztbZztbZztbZ/87W2c7W2c7W2ZSUlP///wDBAB4"
            S"eHh4eHs7W2c7W2c7W2c7W2c7W2f/O1tnO1tnO1tnO1tmUlJT///8AwQAeHh4eHh7O1tnO1tnO1tnO1tn/ztbZHh4eHh4eHh4eHh4eH"
            S"h4e////AIAAHh4eHh4eztbZztbZztbZ/87W2ZSUlP///wDBAADBAADBAADBAADBAACAAB4eHh4eHs7W2c7W2f/O1tnO1tmUlJT///8"
            S"AwQAAgAAeHh4eHh7O1tnO1tnO1tnO1tnO1tn/ztbZztbZztbZlJSU////AMEAAIAAHh4eHh4eztbZztbZztbZztbZ/87W2c7W2c7W2"
            S"c7W2ZSUlP///wDBAACAAB4eHh4eHs7W2c7W2c7W2f/O1tnO1tnO1tnO1tnO1tmUlJT///8AwQAAgAAeHh4eHh7O1tnO1tn/ztbZztb"
            S"ZztbZztbZztbZztbZlJSU////AMEAAIAAHh4eHh4eztbZ/87W2c7W2c7W2c7W2c7W2c7W2c7W2ZSUlP///wDBAACAAB4eHs7W2f/O1"
            S"tnO1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tnO1tn/Cw==";
        img = s;
    }

    // Returns the properties of the specified component extended with a 
    // CategoryAttribute reflecting the name of the type of the property.
    System::ComponentModel::PropertyDescriptorCollection* 
        GetProperties(ITypeDescriptorContext* /*context*/, Object* component, 
        System::Attribute* attributes[])
    {            
        // Obtain an instance of the IEventBindingService.
        IEventBindingService* eventPropertySvc = dynamic_cast<IEventBindingService*>(sp->GetService(__typeof(IEventBindingService)));

        // Return if an IEventBindingService could not be obtained.
        if (eventPropertySvc == 0)             
            return new PropertyDescriptorCollection(0);

        // Obtain the events on the component.
        EventDescriptorCollection* events = 
            TypeDescriptor::GetEvents(component, attributes);       

        // Create an array of the events, where each event is assigned 
        // a category matching its type.
        EventDescriptor* newEvents[] = new EventDescriptor*[events->Count];
        for(int i=0;i < events->Count;i++)
        {
            Attribute* temp[] = {new CategoryAttribute(events->Item[i]->EventType->FullName)};
            newEvents->Item[i] = TypeDescriptor::CreateEvent(events->Item[i]->ComponentType, events->Item[i], temp);
        }
        events = new EventDescriptorCollection(newEvents);

        // Return event properties for the event descriptors.
        return eventPropertySvc->GetEventProperties(events);
    }        

    // Provides the name for the event property tab.
    __property String* get_TabName()
    {
        return S"Events by Type";
    }


    // Provides an image for the event property tab.
    __property System::Drawing::Bitmap* get_Bitmap()
    {
        System::Drawing::Bitmap* bmp = new System::Drawing::Bitmap(DeserializeFromBase64Text(img));
        return bmp;
    }

    // This method can be used to retrieve an Image from a block of 
    // Base64-encoded text.
private:
    Image* DeserializeFromBase64Text(String* text)
    {
        Image* img = 0;
        Byte memBytes[] = Convert::FromBase64String(text);
        IFormatter* formatter = new BinaryFormatter();
        MemoryStream* stream = new MemoryStream(memBytes);
        img = dynamic_cast<Image*>(formatter->Deserialize(stream));
        stream->Close();
        return img;
    }
};

[Visual Basic, JScript] Visual Basic および JScript のサンプルはありません。C# および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Windows.Forms.Design

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System.Windows.Forms (System.Windows.Forms.dll 内)

参照

EventsTab メンバ | System.Windows.Forms.Design 名前空間