共用方式為


EventsTab 類別

定義

提供可以顯示選取範圍和連結 (Linking) 之事件的 PropertyTab

public ref class EventsTab : System::Windows::Forms::Design::PropertyTab
public class EventsTab : System.Windows.Forms.Design.PropertyTab
type EventsTab = class
    inherit PropertyTab
Public Class EventsTab
Inherits PropertyTab
繼承
EventsTab

範例

下列程式碼範例提供範例 EventsTab 。 選取時,會 EventsTab 依委派類型的順序列出元件上的任何事件。

#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;

ref class TypeEventsTab;

// This component adds a TypeEventsTab to the Properties Window.

[PropertyTabAttribute(TypeEventsTab::typeid,PropertyTabScope::Document)]
public ref class TypeEventsTabComponent: public Component
{
public:
   TypeEventsTabComponent(){}

};


// This example events tab lists events by their delegate type.
[System::Security::Permissions::PermissionSetAttribute
      (System::Security::Permissions::SecurityAction::InheritanceDemand, Name="FullTrust")]
[System::Security::Permissions::PermissionSetAttribute
      (System::Security::Permissions::SecurityAction::Demand, Name="FullTrust")]
public ref class TypeEventsTab: public System::Windows::Forms::Design::EventsTab
{
private:

   // This string contains a Base-64 encoded and serialized example 
   // property tab image.

   [BrowsableAttribute(true)]
   String^ img;
   IServiceProvider^ sp;

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

   // Returns the properties of the specified component extended with a 
   // CategoryAttribute reflecting the name of the type of the property.
   virtual System::ComponentModel::PropertyDescriptorCollection^ GetProperties( ITypeDescriptorContext^ /*context*/, Object^ component, array<System::Attribute^>^attributes ) override
   {
      // Obtain an instance of the IEventBindingService.
      IEventBindingService^ eventPropertySvc = dynamic_cast<IEventBindingService^>(sp->GetService( IEventBindingService::typeid ));
      
      // Return if an IEventBindingService could not be obtained.
      if ( eventPropertySvc == nullptr )
            return gcnew PropertyDescriptorCollection( nullptr );

      // 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.
      array<EventDescriptor^>^newEvents = gcnew array<EventDescriptor^>(events->Count);
      for ( int i = 0; i < events->Count; i++ )
      {
         array<Attribute^>^temp = {gcnew CategoryAttribute( events[ i ]->EventType->FullName )};
         newEvents[ i ] = TypeDescriptor::CreateEvent( events[ i ]->ComponentType, events[ i ], temp );
      }
      events = gcnew EventDescriptorCollection( newEvents );

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

   property String^ TabName 
   {
      // Provides the name for the event property tab.
      virtual String^ get() override
      {
         return "Events by Type";
      }
   }

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

private:

   // This method can be used to retrieve an Image from a block of 
   // Base64-encoded text.
   Image^ DeserializeFromBase64Text( String^ text )
   {
      Image^ img = nullptr;
      array<Byte>^memBytes = Convert::FromBase64String( text );
      IFormatter^ formatter = gcnew BinaryFormatter;
      MemoryStream^ stream = gcnew MemoryStream( memBytes );
      img = dynamic_cast<Image^>(formatter->Deserialize( stream ));
      stream->Close();
      return img;
   }
};
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

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;
        }
    }
}

建構函式

EventsTab(IServiceProvider)

初始化 EventsTab 類別的新執行個體。

屬性

Bitmap

取得顯示 PropertyTab 的點陣圖。

(繼承來源 PropertyTab)
Components

取得或設定屬性索引標籤與其關聯的元件陣列。

(繼承來源 PropertyTab)
HelpKeyword

取得索引標籤的 Help 關鍵字。

TabName

取得索引標籤的名稱。

方法

CanExtend(Object)

取得值,表示指定的物件是否能擴充。

Dispose()

釋放 PropertyTab 使用的所有資源。

(繼承來源 PropertyTab)
Dispose(Boolean)

釋放 PropertyTab 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

(繼承來源 PropertyTab)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetDefaultProperty(Object)

從指定的物件取得預設屬性。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetProperties(ITypeDescriptorContext, Object, Attribute[])

取得事件索引標籤中符合指定的屬性和內容的所有屬性。

GetProperties(Object)

取得指定元件的屬性。

(繼承來源 PropertyTab)
GetProperties(Object, Attribute[])

取得符合指定屬性 (Attribute) 之事件索引標籤的所有屬性。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於