我正在尝试设计我的定制 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在代码中,它工作正常。
我在设计时得到了 MessageBox 并且出现了 CheckBox。问题是当我将 SearchOptionsEnum 更改为 List<bool>
时和编辑器默认 Boolean Collection Editor
.
然后CheckBox没有出现,甚至放在set属性中的debbuger断点也不止于此......
问题出在哪里?
此外:当我在编辑器中编辑 bool 值时,它会记住它并保留值。即使在下一个调试 session 中,之前设置的值也会保留。
编辑
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 上的面板。
最佳答案
控件仅在设置了 Parent 时出现。您应该将 _tempCheck 的父级设置为此。
CheckBox _tempCheck = new CheckBox();
_tempCheck.Parent = this;
_tempCheck.Checked = true;
_tempCheck.Location = new Point(x, y);
关于c# - UserControl - 将值设置为属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32044654/