UITypeEditor的一些问题..

MOmo400 2009-04-28 09:21:43
class myeditor : UITypeEditor
{
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (edSvc != null)
{
Form4 f = new Form4();
// your setting here
edSvc.ShowDialog(f);
return f.MyValue;
}
return base.EditValue(context, provider, value);
}
}

重写EditValue这个方法的时候,有一个问题.比如我想不同的属性弹出不同的对话框,难道就要写多个不同的Editor吗?

比如:
Test 属性我用了上面的editor,点击按钮时弹出Form4
[EditorAttribute(typeof(myeditor), typeof(System.Drawing.Design.UITypeEditor))]
public string Test
{
get { return test}
set { test = value; }
}

假如有还想有
[EditorAttribute(typeof(myeditor), typeof(System.Drawing.Design.UITypeEditor))]
public string Test1
{
get { return test1}
set { test = value; }
}
这个属性,点击按钮时弹出不是Form4,难道要再写一个以下 Class吗?

class myeditor1 : UITypeEditor
{
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (edSvc != null)
{
Form5 f = new Form5();
// your setting here
edSvc.ShowDialog(f);
return f.MyValue;
}
return base.EditValue(context, provider, value);
}
}
...全文
118 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
MOmo400 2009-04-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 matee 的回复:]
参考1

[/Quote]

里面用的是
if....else 判断,有更好的方法吗?
matee 2009-04-28
  • 打赏
  • 举报
回复

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧