在属性网格中隐藏可扩展属性的省略号(...)按钮,例如font属性的"..."按钮 [英] Hide ellipsis (…) button of expandable property like “…” button of font property in the property grid
问题描述
我已经在我的自定义控件中添加了一个新属性,作为可扩展属性,如Property Grid中的font属性.在Windows窗体应用程序项目中使用自定义控件后,在属性网格"中看到一个省略号(...)按钮,如font属性的"..."按钮. (有关更多信息,请参见下图.)
我的一个自定义控件属性 [
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.)
One of my custom control properties[^]
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);
}
}
推荐答案
这不是属性网格的工作方式和自定义方式.您不显示或隐藏网格特征,而是更改数据模型.这个想法是:您分配PropertyGrid
的SelectedObject
属性,它表示您的对象.如何自定义它:您使用一些不同的对象,这些对象仅通过实现接口System.ComponentModel.ICustomTypeDescriptor
间接表示您的目标对象.这样,您可以禁用显示.NET Framework类库(FCL)中已经可用的字体对象的自定义编辑器,并以某种不同的方式显示字体:例如,您可以将字体显示为网格的子节点.树,并将其属性显示为单独的子节点.
在我过去的回答中更详细地描述了这种技术:
如何在单击PropertyGrid时获得响应 [ ^ ].
—SA
This is not how property grid works and customized. You don''t show or hide the grid features, you change the data model. The idea is: you assignSelectedObject
property of thePropertyGrid
, and it presents your object. How to customize it: you use some different object, which only represents your target object indirectly, through implementing of the interfaceSystem.ComponentModel.ICustomTypeDescriptor
. This way, you can disable showing the custom editor for font object already available in the .NET Framework Class Library (FCL), and present the font in some different way: for example, you can show a font as a child node of the grid tree, and show its properties as separate sub-nodes.
This technique is described in more detain in my past answer:
How to get response when click PropertyGrid[^].
—SA
我解决了我的问题.对于我已应用于自定义控件的" SimilarFloorsInfo "属性的以下代码行(属性),显示了省略号(...)按钮:
I solved my problem. 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.
这篇关于在属性网格中隐藏可扩展属性的省略号(...)按钮,例如font属性的"..."按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!