如何在自定义数据源组件中为自定义属性提供UIEditor
2009-09-19 00:00:00 来源:WEB开发网到这里为止,我们准备好了一个用于编辑的窗体,现在回到MyTypeUIEditor这个类型,修改它的EditValue方法
public class MyTypeUIEditor : System.Drawing.Design.UITypeEditor {
/// <summary>
/// 这个方法会被自动调用。
/// </summary>
/// <param name="context"></param>
/// <param name="provider"></param>
/// <param name="value">这是组件现有值</param>
/// <returns>要返回给组件的值</returns>
public override object EditValue(
System.ComponentModel.ITypeDescriptorContext context,
IServiceProvider provider,
object value)
{
string current = "目前没有选择目录";
if (value != null)
current = value.ToString();
MyUIEditorForm form = new MyUIEditorForm(current);
if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
return form.Path;
}
return current;
}
public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
}
更多精彩
赞助商链接