EventsTab Class

EventsTab Class

Provides a PropertyTab that can display events for selection and linking.

Namespace:  System.Windows.Forms.Design
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

[PermissionSetAttribute(SecurityAction::LinkDemand, Name = L"FullTrust")]
[PermissionSetAttribute(SecurityAction::InheritanceDemand, Name = L"FullTrust")]
public ref class EventsTab : public PropertyTab

The following code example provides an example EventsTab. When selected, the EventsTab lists any events on a component in order of delegate type.

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

public ref class TypeEventsTabComponent: public Component


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

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

   String^ img;
   IServiceProvider^ sp;

   TypeEventsTab( IServiceProvider^ sp )
      : EventsTab( sp )
      this->sp = sp;
      String^ s = "AAEAAAD/////AQAAAAAAAAAMAgAAAFRTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj0xLjAuMzMwMC4w" 
      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;


   // 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 ));
      return img;


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

© 2015 Microsoft