如何在运行时打开没有PropertyGrid的复杂属性的属性对话框 [英] How to open the properties dialog for a Complex Property without a PropertyGrid at runtime
问题描述
考虑使用一些自定义表单用户控件
和按钮
。
Consider a form with some custom UserControl
and a Button
.
在Visual Studio设计,您可以点击按钮关闭你的财产的权利(就像您当您更改上的控件等常见的属性,如字体
或图片
),并使用该属性的编辑器。
In Visual Studio designer, you can click the button off to the right of your property (like you would when you change other common properties on controls such as Font
or Image
) and use the Editor for this property.
在运行期间,如果你已经添加了一个的PropertyGrid
来的形式和它指向这个用户控件
,您也可以点击按钮关闭在运行时的复杂属性的权利,并获得相同的 UITypeEditor的
对话框。
During runtime, if you've added a PropertyGrid
to the form and point it to this UserControl
, you can also click the button off to the right of that complex property at runtime and get the same UITypeEditor
dialog.
我怎样才能得到这个编辑器窗口,通过比如,点击一个按钮在运行时拿出而无需的PropertyGrid
上表格?
How can I get this editor window to come up during run-time through say, a button click without having a PropertyGrid
on the form?
虽然我已经得到了的PropertyDescriptor
和 UITypeEditor的
从这个描述,我不知道什么叫得到> ITypeDescriptorContext
的IServiceProvider < 。code> UITypeEditor.EditValue 去显示编辑
Though I've gotten the PropertyDescriptor
and the UITypeEditor
from this descriptor, I don't know what to call to get the instances of ITypeDescriptorContext
and IServiceProvider
when calling UITypeEditor.EditValue
to get the editor to display.
这是关系到建设一个属性自定义UITypeEditor的:< A HREF =http://msdn.microsoft.com/en-us/magazine/cc164145.aspx相对=nofollow称号=建立Windows窗体控件和组件具有丰富的设计时功能>建筑Windows窗体控件和组件具有丰富的设计时功能。在这种情况下,我已经配置了这一切,这一切精美的作品,所以我只是想打电话给在运行时,编辑器窗口。
This is related to building a custom UITypeEditor for a property: Building Windows Forms Controls and Components with Rich Design-Time Features. In this case, I've already configured all of this and it all works beautifully so I just want to call the editor window at runtime.
推荐答案
我你设法实施 TypeDescriptor
,你几乎完成结果
这可能是你一个开始:
I you had managed to implement a TypeDescriptor
, you almost done.
This may be a start for you:
public class MyEditor: UITypeEditor {
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) {
return UITypeEditorEditStyle.DropDown;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) {
IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (service != null) {
SomeControl ctrl = new SomeControl();
ctrl.XYZ = ...
service.DropDownControl(ctrl);
value = ctrl.XYZ;
}
return value;
}
的WinForms处理它的其余部分。
WinForms handles the rest of it.
返回 UITypeEditorEditStyle.Modal
表格 GetEditStyle
,也可以使用 service.ShowDialog (CTRL)
,如果你有一个形式,而不是控制。
Return UITypeEditorEditStyle.Modal
form GetEditStyle
and also use service.ShowDialog(ctrl)
, if you have a form instead of a control.
这篇关于如何在运行时打开没有PropertyGrid的复杂属性的属性对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!