Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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 = "FullTrust")]
[PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
public class EventsTab : PropertyTab

The EventsTab type exposes the following members.

  NameDescription
Public methodEventsTabInitializes a new instance of the EventsTab class.
Top
  NameDescription
Public propertyBitmapGets the bitmap that is displayed for the PropertyTab. (Inherited from PropertyTab.)
Public propertyComponentsGets or sets the array of components the property tab is associated with. (Inherited from PropertyTab.)
Public propertyHelpKeywordGets the Help keyword for the tab. (Overrides PropertyTab.HelpKeyword.)
Public propertyTabNameGets the name of the tab. (Overrides PropertyTab.TabName.)
Top
  NameDescription
Public methodCanExtendGets a value indicating whether the specified object can be extended. (Overrides PropertyTab.CanExtend(Object).)
Public methodDispose()Releases all the resources used by the PropertyTab. (Inherited from PropertyTab.)
Protected methodDispose(Boolean)Releases the unmanaged resources used by the PropertyTab and optionally releases the managed resources. (Inherited from PropertyTab.)
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows a PropertyTab to attempt to free resources and perform other cleanup operations before the PropertyTab is reclaimed by garbage collection. (Inherited from PropertyTab.)
Public methodGetDefaultPropertyGets the default property from the specified object. (Overrides PropertyTab.GetDefaultProperty(Object).)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetProperties(Object)Gets the properties of the specified component. (Inherited from PropertyTab.)
Public methodGetProperties(Object, Attribute[])Gets all the properties of the event tab that match the specified attributes. (Overrides PropertyTab.GetProperties(Object, Attribute[]).)
Public methodGetProperties(ITypeDescriptorContext, Object, Attribute[])Gets all the properties of the event tab that match the specified attributes and context. (Overrides PropertyTab.GetProperties(ITypeDescriptorContext, Object, Attribute[]).)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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;
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.
    [System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.InheritanceDemand, Name="FullTrust")]
    [System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
    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;
        }
    }
}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.