如何在c#中双击控件打开模态对话框

时间:2011-01-25 02:15:05

标签: c# controls design-time

我正在为c#(WinForms)编写一个控件,我有一个Collection类型的属性。

当用户选择此属性时,将显示带有“...”的按钮,并打开新的模态对话框。所有这一切都很好,我创造了:

public class ItemsEditor : UITypeEditor

在这个课程中,我重写了EditValue方法,并使用ShowDialog打开了模态编辑器。正如我所说,这项工作很好。

但是,我想在控件用户双击它时打开此对话框。

为此我继承了ControlDesigner:

public class MyControlDesigner : ControlDesigner

在这个课程中我继承了下一个方法:

public override void DoDefaultAction()
{
    string propertyName = "Items";                      
    IServiceProvider provider = (IServiceProvider)GetService(typeof(IServiceProvider));      

    PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(MyControl);

    PropertyDescriptor property = properties[propertyName];

    UITypeEditor editor = (UITypeEditor)property.GetEditor(typeof(UITypeEditor));

    editor.EditValue(provider, null);
}

可以看出,我已经放了一些随机代码,当然不行。

有人可以帮我解决这个问题,以及如何双击打开属性。

感谢您的帮助

祝你好运 博

1 个答案:

答案 0 :(得分:0)

我不确定双击显示编辑器的可行性,但另一种方法可能是使用ActionLists又名SmartTag - 请参阅文章:http://msdn.microsoft.com/en-us/library/ms171829.aspx

相关问题