UserControl - 将值设置为property

时间:2015-08-17 07:13:56

标签: c# winforms user-controls remote-debugging design-time

我正在尝试为UserControl应用程序设计自定义WinForms。我曾经创建过自定义的枚举属性,当用户在设计时更改属性值时,该属性可以完美地创建一个CheckBox

    private SearchOptionsEnum _searchAreas;
    //private List<bool> _searchAreas = new List<bool>();
    [Description(""), Category("GostcompSettings")]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    [Editor(typeof(Utils.FlagEnumUIEditor), typeof(UITypeEditor))]
    public SearchOptionsEnum SearchAreas
    //public List<bool> SearchAreas
    {
        get
        {
            return _searchAreas;
        }
        set
        {

            _searchAreasChceckBoxList.Clear();
            pPanelWithCheckboxies.Controls.Clear();
            int x = 10;
            int y = 10;

            CheckBox _tempCheck = new CheckBox();
            _tempCheck.Checked = true;
            _tempCheck.Location = new Point(x, y);

            _searchAreasChceckBoxList.Add(_tempCheck);
            pPanelWithCheckboxies.Controls.Add(_tempCheck);

            MessageBox.Show("zmiana");
            _searchAreas = value;
        }
    }

我在代码中使用自定义值编辑器UITypeEditor,它工作正常。

我在Design-Time中获得MessageBox并出现CheckBox。问题是我将SearchOptionsEnum更改为List<bool>并将编辑器更改为默认Boolean Collection Editor

然后CheckBox没有出现,甚至在set属性中输入的debbuger断点也不止于此......

问题出在哪里?

此外:当我在编辑器中编辑bool值时,它会记住它并保留值。即使在下一个调试会话中,也会保留之前设置的值。

修改

public partial class StudySearchAndView : UserControl
{
    private List<CheckBox> _searchAreasChceckBoxList = new List<CheckBox>();

    private SearchOptionsEnum _searchAreas;
    //private List<bool> _searchAreas = new List<bool>();
    [Description(""), Category("GostcompSettings")]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    [Editor(typeof(Utils.FlagEnumUIEditor), typeof(UITypeEditor))]
    public SearchOptionsEnum SearchAreas
    //public List<bool> SearchAreas
    {
        get
        {
            return _searchAreas;
        }
        set
        {

            _searchAreasChceckBoxList.Clear();
            pPanelWithCheckboxies.Controls.Clear();
            int x = 10;
            int y = 10;

            CheckBox _tempCheck = new CheckBox();
            _tempCheck.Checked = true;
            _tempCheck.Location = new Point(x, y);

            _searchAreasChceckBoxList.Add(_tempCheck);
            pPanelWithCheckboxies.Controls.Add(_tempCheck);

            MessageBox.Show("zmiana");
            _searchAreas = value;
        }
    }

}

pPanelWithCheckboxies只是一个放在UserControl上的面板。

0 个答案:

没有答案