如何在 C# 中双击控件打开模式对话框
我正在为 c# (WinForms) 编写一个控件,并且我有一个 Collection 类型的属性。
当用户选择此属性时,将显示带有“...”的按钮,并打开新的模式对话框。所有这些工作正常,我已经创建:
public class ItemsEditor : UITypeEditor
在这个类中,我重写了 EditValue 方法并使用 ShowDialog 打开模式编辑器。正如我所说,这工作正常。
但是,我想在控件用户双击它时打开此对话框。
为此,我继承了 ControlDesigner:
public class MyControlDesigner : ControlDesigner
并且在这个类中我继承了 next 方法:
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);
}
正如您所看到的,我放置了一些随机代码,当然不起作用。
有人可以帮我解决这个问题,以及如何双击打开属性。
感谢您的所有帮助
诚挚的问候 博扬
I am writing a control for c# (WinForms) and I have one property of Collection type.
When user select this property, button with "..." will be shown and new modal dialog will open. All this work fine, I have create:
public class ItemsEditor : UITypeEditor
In this class I have override EditValue method and open modal editor with ShowDialog. As I say this work fine.
But, I want to open this dialog when user of control double-click on it.
For this purpose I have inherit ControlDesigner:
public class MyControlDesigner : ControlDesigner
and in this class I have inherit next method:
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);
}
As may be seen, I have put some random code and of course don't work.
Can somebody help me how to solve this, and how to open property on double-click.
Thank you for all help
Best regards
Bojan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定双击显示编辑器的可行性,但另一种方法可能是使用 ActionLists 又名 SmartTag - 请参阅文章:http://msdn.microsoft.com/en-us/library/ms171829.aspx
I am not certain about feasibility of showing the editor on double click but one of other way could be using ActionLists aka SmartTag - please see article: http://msdn.microsoft.com/en-us/library/ms171829.aspx