问题描述
我在自定义控件中添加了一个新属性,作为可扩展属性,例如属性网格中的字体属性。从Windows窗体应用程序项目中的自定义控件使用后,我在属性网格中看到一个省略号(...)按钮,如font属性的 ...按钮。 (有关更多信息,请参见下图。)
现在,我想隐藏新扩展属性的省略号(...)按钮。
可扩展的属性代码为:
[DisplayName( Floors Information)]
[ Description( Floors Informationnnnnnnnnnnnnnnn)]
[DefaultProperty( TitleText)]
[DesignerCategory( Component)]
公共类FloorsInformation:DockContainerItem
{
私人的SameFloorsInformation类似的FloorsInformation =新的相似的FloorsInformation();
public FloorsInformation()
{
}
[Category( Data)]
[DisplayName(相似楼层面板)]
[说明(相似楼层面板lllllllllllllllllllll)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor(typeof(ItemsCollectionEditor),typeof(UITypeEditor))]
// [TypeConverter(typeof(ExpandableObjectConverter))]
// [TypeConverter(typeof(SimilarFloorsInformationTypeConverter))]
public SameFloorsInformation SameFloorsInfo
{
get
{
return sameFloorsInformation;
}
}
}
[DisplayName(相似楼层信息)]
[Description(相似楼层信息nnnnnnnnnnnnnnn)]
[DefaultProperty( Text)]
[DesignerCategory( Component)]
[TypeConverter(typeof(SimilarFloorsInformationTypeConverter))]
// [TypeConverter(typeof(ExpandableObjectConverter))] $ b b $ b public class SameFloorsInformation:ExpandablePanel
{
private Color canvasColor = SystemColors.Control;
私人eCollapseDirection crashDirection = eCollapseDirection.LeftToRight;
private eDotNetBarStyle colorSchemeStyle = eDotNetBarStyle.StyleManagerControlled;
私人DockStyle基座= DockStyle.Right;
私人eTitleButtonAlignment expandButtonAlignment = eTitleButtonAlignment.Left;
私人布尔扩展=假;
private bool markupUsesStyleAlignment = true;
private Size size = new Size(30,177);
public SameFloorsInformation()
{
}
}
public class SimilarFloorsInformationTypeConverter:ExpandableObjectConverter // TypeConverter
{
公共重写bool CanConvertTo(ITypeDescriptorContext上下文,类型destinationType)
{
if(destinationType == typeof(SimilarFloorsInformation))
{
返回true;
}
返回base.CanConvertTo(context,destinationType);
}
公共重写对象ConvertTo(ITypeDescriptorContext上下文,CultureInfo文化,对象值,类型destinationType)
{
if(destinationType == typeof(String)& &值是 SimilarFloorsInformation)
{
LikeFloorsInformation similarFloorsInformation =(SimilarFloorsInformation)value;
return sameFloorsInformation.TitleText;
}
返回base.ConvertTo(context,culture,value,destinationType);
}
公共重写bool CanConvertFrom(ITypeDescriptorContext context,type sourceType)
{
if(sourceType == typeof(string))
{
返回true;
}
返回base.CanConvertFrom(context,sourceType);
}
公共替代对象ConvertFrom(ITypeDescriptorContext上下文,CultureInfo文化,对象值)
{
if(值是字符串)
{
SimilarFloorsInformation similarFloorsInformation = new LikeFloorsInformation();
similarFloorsInformation.TitleText =(string)value;
return sameFloorsInformation;
}
返回base.ConvertFrom(上下文,文化,价值);
}
}
I根据Nikolay Khil的回答解决了我的问题。对于我已应用于自定义控件的 SimilarFloorsInfo 属性的以下代码行(属性),显示了省略号(...)按钮:
[Editor(typeof(ItemsCollectionEditor),typeof(UITypeEditor))]
因此,必须删除或注释此行代码。现在,在属性网格中没有为我的属性显示省略号(...)按钮。
I've added a new property to my custom control as expandable property like font property in Property Grid. After using from my custom control in a Windows Forms Application project, I see an ellipsis (…) button like "…" button of font property in Property Grid. (For more information, please see the following picture.)
Now, I want to hide the ellipsis (…) button for my new expandable property.
Expandable property codes are:
[DisplayName("Floors Information")]
[Description("Floors Informationnnnnnnnnnnnnnnn")]
[DefaultProperty("TitleText")]
[DesignerCategory("Component")]
public class FloorsInformation : DockContainerItem
{
private SimilarFloorsInformation similarFloorsInformation = new SimilarFloorsInformation();
public FloorsInformation()
{
}
[Category("Data")]
[DisplayName("Similar Floors Panel")]
[Description("Similar Floors Panellllllllllllllllllll")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor(typeof(ItemsCollectionEditor), typeof(UITypeEditor))]
//[TypeConverter(typeof(ExpandableObjectConverter))]
//[TypeConverter(typeof(SimilarFloorsInformationTypeConverter))]
public SimilarFloorsInformation SimilarFloorsInfo
{
get
{
return similarFloorsInformation;
}
}
}
[DisplayName("Similar Floors Information")]
[Description("Similar Floors Informationnnnnnnnnnnnnnnn")]
[DefaultProperty("Text")]
[DesignerCategory("Component")]
[TypeConverter(typeof(SimilarFloorsInformationTypeConverter))]
//[TypeConverter(typeof(ExpandableObjectConverter))]
public class SimilarFloorsInformation : ExpandablePanel
{
private Color canvasColor = SystemColors.Control;
private eCollapseDirection collapseDirection = eCollapseDirection.LeftToRight;
private eDotNetBarStyle colorSchemeStyle = eDotNetBarStyle.StyleManagerControlled;
private DockStyle dock = DockStyle.Right;
private eTitleButtonAlignment expandButtonAlignment = eTitleButtonAlignment.Left;
private bool expanded = false;
private bool markupUsesStyleAlignment = true;
private Size size = new Size(30, 177);
public SimilarFloorsInformation()
{
}
}
public class SimilarFloorsInformationTypeConverter : ExpandableObjectConverter//TypeConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(SimilarFloorsInformation))
{
return true;
}
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(String) && value is SimilarFloorsInformation)
{
SimilarFloorsInformation similarFloorsInformation = (SimilarFloorsInformation)value;
return similarFloorsInformation.TitleText;
}
return base.ConvertTo(context, culture, value, destinationType);
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string)
{
SimilarFloorsInformation similarFloorsInformation = new SimilarFloorsInformation();
similarFloorsInformation.TitleText = (string)value;
return similarFloorsInformation;
}
return base.ConvertFrom(context, culture, value);
}
}
I solved my problem according to Nikolay Khil answer. Ellipsis (...) button is shown for following line of code (Attribute) that I've applied to the "SimilarFloorsInfo" property of my custom control:
[Editor(typeof(ItemsCollectionEditor), typeof(UITypeEditor))]
So, this line of code must be deleted or commented. Now, Ellipsis (...) button not shown for my property in the property grid.
这篇关于隐藏可扩展属性(例如“…”)的省略号(...)按钮属性网格中的字体属性按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!