【问题标题】:How to open modal dialog on control double click in c#如何在c#中控制双击打开模态对话框
【发布时间】:2011-01-25 02:15:05
【问题描述】:

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

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

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

感谢大家的帮助

最好的问候 博扬

【问题讨论】:

  • 抱歉,请改写您的问题。这很难理解。
  • 例如:当你双击 ListView 控件时 - 应该打开列编辑器。

标签: c# controls design-time


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多