PropertyTab 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为属性选项卡提供基类。
public ref class PropertyTab abstract : System::ComponentModel::IExtenderProvider
public abstract class PropertyTab : System.ComponentModel.IExtenderProvider
type PropertyTab = class
interface IExtenderProvider
Public MustInherit Class PropertyTab
Implements IExtenderProvider
- 继承
-
PropertyTab
- 派生
- 实现
示例
下面的代码示例提供了一个示例 PropertyTab ,其中列出了按类型名称排列的组件上的任何属性。
#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::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;
using namespace System::Security::Permissions;
namespace TypeCategoryTabExample
{
ref class TypeCategoryTab;
// forward declaration.
// This component adds a TypeCategoryTab to the propery browser
// that is available for any components in the current design mode document.
[PropertyTabAttribute(TypeCategoryTabExample::TypeCategoryTab::typeid,PropertyTabScope::Document)]
public ref class TypeCategoryTabComponent: public System::ComponentModel::Component
{
public:
TypeCategoryTabComponent(){}
};
// A TypeCategoryTab property tab lists properties by the
// category of the type of each property.
public ref class TypeCategoryTab: public PropertyTab
{
private:
// This String^ contains a Base-64 encoded and serialized example property tab image.
[BrowsableAttribute(true)]
String^ img;
public:
TypeCategoryTab()
{
img = "AAEAAAD/////AQAAAAAAAAAMAgAAAFRTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj0xLjAuMzMwMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABVTeXN0ZW0uRHJhd2luZy5CaXRtYXABAAAABERhdGEHAgIAAAAJAwAAAA8DAAAA9gAAAAJCTfYAAAAAAAAANgAAACgAAAAIAAAACAAAAAEAGAAAAAAAAAAAAMQOAADEDgAAAAAAAAAAAAD///////////////////////////////////9ZgABZgADzPz/zPz/zPz9AgP//////////gAD/gAD/AAD/AAD/AACKyub///////+AAACAAAAAAP8AAP8AAP9AgP////////9ZgABZgABz13hz13hz13hAgP//////////gAD/gACA/wCA/wCA/wAA//////////+AAACAAAAAAP8AAP8AAP9AgP////////////////////////////////////8L";
}
// Returns the properties of the specified component extended with
// a CategoryAttribute reflecting the name of the type of the property.
[ReflectionPermission(SecurityAction::Demand, Flags=ReflectionPermissionFlag::MemberAccess)]
virtual System::ComponentModel::PropertyDescriptorCollection^ GetProperties( Object^ component, array<System::Attribute^>^attributes ) override
{
PropertyDescriptorCollection^ props;
if ( attributes == nullptr )
props = TypeDescriptor::GetProperties( component );
else
props = TypeDescriptor::GetProperties( component, attributes );
array<PropertyDescriptor^>^propArray = gcnew array<PropertyDescriptor^>(props->Count);
for ( int i = 0; i < props->Count; i++ )
{
// Create a new PropertyDescriptor from the old one, with
// a CategoryAttribute matching the name of the type.
array<Attribute^>^temp0 = {gcnew CategoryAttribute( props[ i ]->PropertyType->Name )};
propArray[ i ] = TypeDescriptor::CreateProperty( props[ i ]->ComponentType, props[ i ], temp0 );
}
return gcnew PropertyDescriptorCollection( propArray );
}
virtual System::ComponentModel::PropertyDescriptorCollection^ GetProperties( Object^ component ) override
{
return this->GetProperties( component, nullptr );
}
property String^ TabName
{
// Provides the name for the property tab.
virtual String^ get() override
{
return "Properties by Type";
}
}
};
}
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms.Design;
namespace TypeCategoryTabExample;
// This component adds a TypeCategoryTab to the property browser
// that is available for any components in the current design mode document.
[PropertyTab(typeof(TypeCategoryTab), PropertyTabScope.Document)]
public class TypeCategoryTabComponent : Component
{
public TypeCategoryTabComponent()
{
}
}
// A TypeCategoryTab property tab lists properties by the
// category of the type of each property.
public class TypeCategoryTab : PropertyTab
{
public TypeCategoryTab()
{
}
// Returns the properties of the specified component extended with
// a CategoryAttribute reflecting the name of the type of the property.
public override PropertyDescriptorCollection GetProperties(object component, System.Attribute[] attributes)
{
PropertyDescriptorCollection props = attributes == null ? TypeDescriptor.GetProperties(component) : TypeDescriptor.GetProperties(component, attributes);
PropertyDescriptor[] propArray = new PropertyDescriptor[props.Count];
for (int i = 0; i < props.Count; i++)
{
// Create a new PropertyDescriptor from the old one, with
// a CategoryAttribute matching the name of the type.
propArray[i] = TypeDescriptor.CreateProperty(props[i].ComponentType, props[i], new CategoryAttribute(props[i].PropertyType.Name));
}
return new PropertyDescriptorCollection(propArray);
}
public override PropertyDescriptorCollection GetProperties(object component) => GetProperties(component, null);
// Provides the name for the property tab.
public override string TabName => "Properties by Type";
// Provides an image for the property tab.
public override Bitmap Bitmap => new("myproperty.bmp", true);
}
注解
PropertyTab 类提供属性选项卡的基类行为。属性选项卡显示在属性窗口的 PropertyGrid 控件的工具栏上,并允许组件显示其属性或其他数据的不同视图。
用户代码通常不会直接创建实例 PropertyTab 。 相反, PropertyTabAttribute 指示要为组件显示的属性选项卡或属性选项卡的类型可以与应为其显示的属性或类型 PropertyTab 相关联。
它将 PropertyGrid 实例化 PropertyTab 由 PropertyTabAttribute 与正在浏览的组件的类型或属性字段关联的类型。
构造函数
| 名称 | 说明 |
|---|---|
| PropertyTab() |
初始化 PropertyTab 类的新实例。 |
属性
| 名称 | 说明 |
|---|---|
| Bitmap |
获取为该 PropertyTab位置显示的位图。 |
| Components |
获取或设置属性选项卡关联的组件数组。 |
| HelpKeyword |
获取要与此选项卡关联的帮助关键字。 |
| TabName |
获取属性选项卡的名称。 |
方法
| 名称 | 说明 |
|---|---|
| CanExtend(Object) |
获取一个值,该值指示这是否可以 PropertyTab 显示指定组件的属性。 |
| Dispose() |
释放 PropertyTab使用的所有资源。 |
| Dispose(Boolean) |
释放由托管资源使用 PropertyTab 的非托管资源,并选择性地释放托管资源。 |
| Equals(Object) |
确定指定的对象是否等于当前对象。 (继承自 Object) |
| Finalize() |
PropertyTab允许在垃圾回收回收之前PropertyTab尝试释放资源并执行其他清理操作。 |
| GetDefaultProperty(Object) |
获取指定组件的默认属性。 |
| GetHashCode() |
用作默认哈希函数。 (继承自 Object) |
| GetProperties(ITypeDescriptorContext, Object, Attribute[]) |
获取与指定属性和上下文匹配的指定组件的属性。 |
| GetProperties(Object, Attribute[]) |
获取与指定属性匹配的指定组件的属性。 |
| GetProperties(Object) |
获取指定组件的属性。 |
| GetType() |
获取当前实例的 Type。 (继承自 Object) |
| MemberwiseClone() |
创建当前 Object的浅表副本。 (继承自 Object) |
| ToString() |
返回一个表示当前对象的字符串。 (继承自 Object) |