0

首先我做了什么(更容易解释我想要得到什么):

我创建了一个带有 type 设计器属性的简单用户控件List<bool>

[Browsable(true)]
[Description("Select some.")]
[Category("SelectionTest")]
public List<bool> BoolList = new List<bool>();

当将此控件拖到我的表单上并检查设计器时,我得到以下信息:

在此处输入图像描述

这将打开一个编辑器:

在此处输入图像描述

目标:

我想添加另一个类型的属性,string以便它显示为左侧的显示文本。我不在乎它是否可编辑。

所以总的来说,我需要一些List<string, bool>不可能的东西,我知道。不幸的是Dictionary,并Tuple没有工作。打开编辑器时,它仍然是显示为 的单个值Value: (string, bool)

任何人都知道如何将另一个属性放入正确的窗口或更改布尔值的描述?

非常感谢这里的每一个帮助。我想这将是非常好的知识。想想各种可能性...

谢谢!

4

1 回答 1

1

我知道你想要命名布尔值

public partial class UserControl1 : UserControl
{
    [Browsable(true)]
    [Description("Select some.")]
    [Category("Selection Test"), DisplayName("Bool List")]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    public List<BoolProperty> BoolList { get; set; } = new List<BoolProperty>();

    public UserControl1()
    {
        InitializeComponent();
    }
}

[Serializable]
public class BoolProperty
{
    public string Name { get; set; }

    public bool Value { get; set; }

    public override string ToString()
    {
        return Name ?? "Empty Boolean Property";
    }
}

好像:

好像

于 2017-01-17T14:20:16.263 回答