2

我在自定义控件中添加了一个新属性作为可扩展属性,例如属性网格中的字体属性。在 Windows 窗体应用程序项目中使用我的自定义控件后,我在属性网格中看到一个省略号 (...) 按钮,例如字体属性的“...”按钮。(有关更多信息,请参见下图。)

我的自定义控件属性之一

现在,我想为我的新可扩展属性隐藏省略号 (...) 按钮。

可扩展的属性代码是:

[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);
    }
}
4

2 回答 2

5

您应该实现自己的类派生UITypeEditor并覆盖GetEditStyle方法,如下所示:

public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
    return UITypeEditorEditStyle.None;
}

然后使用EditorAttribute

[Editor(typeof(YourTypeEditor), typeof(UITypeEditor))]

更新1:

好。我刚刚意识到你已经在申请EditorAttribute房产了:

[Editor(typeof(ItemsCollectionEditor), typeof(UITypeEditor))]
public SimilarFloorsInformation SimilarFloorsInfo
{
    get
    {
        return similarFloorsInformation;
    }
}

所以你应该覆盖GetEditStylein ItemsCollectionEditor

于 2012-10-10T20:51:38.177 回答
0

我根据 Nikolay Khil 的回答解决了我的问题。省略号 (...) 按钮显示为我已应用于自定义控件的“ SimilarFloorsInfo ”属性的以下代码行(属性):

[Editor(typeof(ItemsCollectionEditor), typeof(UITypeEditor))]

所以,这行代码必须删除或注释掉。现在,在属性网格中没有为我的属性显示省略号 (...) 按钮。

于 2012-10-12T11:22:51.050 回答