问题
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);
}
}
回答1:
You should implement your own class derived from UITypeEditor and override GetEditStyle method as follows:
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.None;
}
Then use EditorAttribute:
[Editor(typeof(YourTypeEditor), typeof(UITypeEditor))]
Update 1:
Well. I just realized you're already applying EditorAttribute
on the property:
[Editor(typeof(ItemsCollectionEditor), typeof(UITypeEditor))]
public SimilarFloorsInformation SimilarFloorsInfo
{
get
{
return similarFloorsInformation;
}
}
So you should override GetEditStyle
in ItemsCollectionEditor
.
回答2:
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.
来源:https://stackoverflow.com/questions/12826684/hide-ellipsis-button-of-expandable-property-like-button-of-font-property