在msdn上看到这样一个例子,怎么实例化一个类赋给propertygrid怎么不会添加一个选项卡啊,急啊,望高手指点.[PropertyTabAttribute(typeof(TypeCategoryTab), PropertyTabScope.Document)]
public class TypeCategoryTabComponent : System.ComponentModel.Component
{
public TypeCategoryTabComponent()
{
}
} // A TypeCategoryTab property tab lists properties by the
// category of the type of each property.
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
public class TypeCategoryTab : PropertyTab
{
[BrowsableAttribute(true)]
// This string contains a Base-64 encoded and serialized example property tab image.
private string img = "AAEAAAD/////AQAAAAAAAAAMAgAAAFRTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj0xLjAuMzMwMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABVTeXN0ZW0uRHJhd2luZy5CaXRtYXABAAAABERhdGEHAgIAAAAJAwAAAA8DAAAA9gAAAAJCTfYAAAAAAAAANgAAACgAAAAIAAAACAAAAAEAGAAAAAAAAAAAAMQOAADEDgAAAAAAAAAAAAD///////////////////////////////////9ZgABZgADzPz/zPz/zPz9AgP//////////gAD/gAD/AAD/AAD/AACKyub///////+AAACAAAAAAP8AAP8AAP9AgP////////9ZgABZgABz13hz13hz13hAgP//////////gAD/gACA/wCA/wCA/wAA//////////+AAACAAAAAAP8AAP8AAP9AgP////////////////////////////////////8L"; public TypeCategoryTab()
{
} // 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(object component, System.Attribute[] attributes)
{
PropertyDescriptorCollection props;
if( attributes == null )
props = TypeDescriptor.GetProperties(component);
else
props = 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 System.ComponentModel.PropertyDescriptorCollection GetProperties(object component)
{
return this.GetProperties(component, null);
} // Provides the name for the property tab.
public override string TabName
{
get
{
return "Properties by Type";
}
} // Provides an image for the 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;
}
}
}
解决方案 »
- 判断拖入listbox文件的格式
- 麻烦帮把以下的函数由C转为C#
- 小小算法,如何高效实现?比比谁的线代好~~
- 使用.net写的Windows服务调用组件对话框folderBrowserDialog时,界面无法正常显示。
- USB小票打印机弹钱箱问题~
- 用按钮引发的click事件,与菜单引发的click事件有什么不同
- 寻求把一个数组里的数据 插入数据库的合理方法
- C#查找Access指定日期的数据
- LINQ 数据处理。求帮忙。
- http中文utf8编码问题,没分了,外加100元
- multimedia控件我怎么没有啊?我知道在自定义工具箱里,我用的是vs2005的,可是就是找不到啊,怎么办?
- cookies不设置过期时间默认是永远不过期吗?
使用
this.propertyGrid1.PropertyTabs.AddTabType(typeof(TypeCategoryTab));
就可以给propertyGrid1添加一个tab