0

我正在为 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);
}

可以看出,我放了一些随机代码,当然不起作用。

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

谢谢大家的帮助

最好的问候博扬

4

1 回答 1

0

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

于 2011-01-25T04:55:30.703 回答