本文整理汇总了C#中System.Windows.Forms.Design.EventsTab类的典型用法代码示例。如果您正苦于以下问题:C# EventsTab类的具体用法?C# EventsTab怎么用?C# EventsTab使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EventsTab类属于System.Windows.Forms.Design命名空间,在下文中一共展示了EventsTab类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TypeEventsTabComponent
//引入命名空间
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;
}
}
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms.Design,代码行数:103,代码来源:EventsTab
注:本文中的System.Windows.Forms.Design.EventsTab类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论