[英]UserControl - set value to property
I'm trying to design my custom UserControl
for WinForms
applications. 我正在尝试为
WinForms
应用程序设计自定义UserControl
。 I used to create customized enum property that works perfect and creates one CheckBox
when user change property value in design-time. 我曾经创建过自定义的枚举属性,当用户在设计时更改属性值时,该枚举属性可以完美工作并创建一个
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;
}
}
I am using custom value editor UITypeEditor in the code and it works fine. 我在代码中使用自定义值编辑器UITypeEditor ,并且工作正常。
I get MessageBox in Design-Time and CheckBox appears. 我在设计时收到MessageBox并出现CheckBox。 Problem is when I change SearchOptionsEnum to
List<bool>
and editor to default Boolean Collection Editor
. 问题是当我将SearchOptionsEnum更改为
List<bool>
并将编辑器更改为默认Boolean Collection Editor
。
Then the CheckBox does not appear, and even debbuger breakpoint put in the set property does not stop there... 然后CheckBox不会出现,甚至set属性中的debbuger断点也不会在那里停下来。
Where is the problem? 问题出在哪儿?
Moreover: When I edit bool values in editor it memorize it and keeps values. 此外:当我在编辑器中编辑布尔值时,它会记住它并保留值。 Even in next debugging session values set before are kept.
即使在下一个调试会话中,也会保留之前设置的值。
EDIT 编辑
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
is just a panel dropped on UserControl. pPanelWithCheckboxies
只是放置在UserControl上的面板。
Controls appear only if Parent is set. 仅当设置了“父级”时,控件才会出现。 You should set the Parent of _tempCheck to this.
您应该将_tempCheck的Parent设置为此。
CheckBox _tempCheck = new CheckBox();
_tempCheck.Parent = this;
_tempCheck.Checked = true;
_tempCheck.Location = new Point(x, y);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.