Winform user control does not create designer code after user's edit?WinForm自定义控件编辑结果不在窗体代码生成?
我创建了一个名称为MSTagServer的自定义控件,其中有个属性为SavedTagsList,给用户提供弹出窗体编辑需要确认的勾选项。为了能记住用户的勾选项,我想再窗体代码内进行生成,问题是编辑完毕后,窗体代码没有任何的变化。测试过程中,我发现只要移除[Editor(typeof(SavedTagSelectDropDownEditor)这段属性代码,用VS标准的方式编辑,每次关闭,均能在设计器中产生代码记忆编辑内容,但是为何用自定义的编辑窗体就不行呢?
I create a user control named MSTagServer.the control have a property named SavedTagsList which show user the UITypeEditor window to check saved tags.the problem is the desiger does not generate any code like
this.msTagServer1.SavedTagsList.Add(((Advantech.MSControl.SavedTag)(resources.GetObject("msTagServer1.SavedTagsList"))));if I remove the line [Editor(typeof(SavedTagSelectDropDownEditor), typeof(UITypeEditor))],the vs will generate designer codeas soon as the edit windown close.so,what's the problem?why the user's UITypeEditor can not trigger the form deigner?控件代码
public partial class MSTagServer : Component
private List<SavedTag> _list = new List<SavedTag>();
[Editor(typeof(SavedTagSelectDropDownEditor), typeof(UITypeEditor))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<SavedTag> SavedTagsList
{
set
{
_list = value;
if (_list != null && Common.EditEnvironmentCheck() == false)//not edit mode,mark
{
if (TagList.TagsDic.Count > 0)
{
foreach (SavedTag item in _list)
{
TagGroup grp = TagList.TagsDic[item.TagGroupName];
Tag tag = grp.Tags.Find(x => x.TagName.Equals(item.TagName));
tag.SaveToFile = true;
}
}
}
}
get { return _list; }
}
弹出窗体编辑器
public class SavedTagSelectDropDownEditor : System.Drawing.Design.UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
if (context != null && context.Instance != null)
{
return UITypeEditorEditStyle.Modal;
}
return base.GetEditStyle(context);
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
IWindowsFormsEditorService editorService = null;
if (context != null && context.Instance != null && provider != null)
{
editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (editorService != null)
{
MSTagServer ts = (MSTagServer)context.Instance;
if (ts != null)
{
FrmTagSelectControl ctrl = new FrmTagSelectControl(ts.TagDic, ts.SavedTagsList);
DialogResult res = editorService.ShowDialog(ctrl);//show user's edit window
if (res == DialogResult.OK)
{
value = ctrl.SavedTagsList;
return value;
}
}
}
}
return value;
}
}
需要存储在设计器中的类
[Serializable]
public class SavedTag
{
public string TagGroupName { set; get; }
public string TagName { set; get; }
}