【发布时间】:2018-05-21 08:55:48
【问题描述】:
我有一个使用UITypeEditor 的自定义编辑器的属性网格。
我想将其弹出窗口与属性网格的单元格对齐,就像属性为 Color 时的默认颜色编辑器一样,但我找不到有关网格单元格位置和大小的任何信息。
我的UITypeEditor.EditValue 方法得到一个PropertyDescriptorGridEntry 对象作为context 参数,但它也没有坐标,它的GridItems 集合是空的。
有什么想法吗?是否有提供此功能的 PropertyGrid 的(免费)替代品 信息?
这是我当前的代码:
class MyPropertyGridEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle( System.ComponentModel.ITypeDescriptorContext context )
{
return UITypeEditorEditStyle.Modal;
}
// Displays the UI for value selection.
public override object EditValue(
System.ComponentModel.ITypeDescriptorContext context,
System.IServiceProvider provider,
object value )
{
var form = new MyEditorForm( true );
// ??? Where can I find Location and Size of the grid cell ???
if( form.ShowDialog() == DialogResult.OK )
{
value = form.Items;
}
return value;
}
}
以上是我希望我的表单如何对齐的示例,该示例显示了默认的颜色编辑器。
【问题讨论】:
-
默认行为是保持对齐。我无法重现您遇到的问题。考虑发布minimal reproducible example。
-
在我看来像bike-shedding ????。如果你真的想调整,如何使用DevExpress property grid 之类的东西并在他们的源代码中查看如何挂钩弹出创建过程?或者看看the reference source of the original property grid 以更好地理解并可能加入?
-
我添加了示例代码并澄清了屏幕截图仅显示了我的表单应如何对齐的示例。颜色编辑器的对齐没有问题,但我希望我自己的编辑器也能这样显示。
-
@Uwe Klein:我想开源我的程序,所以商业产品是没有选择的。正如我上面所说的。
-
您是否尝试过使用 UITypeEditorEditStyle.DropDown 而不是 Modal,以及 IWindowsFormsEditorService.DropDownControl 而不是显示表单?这就是颜色编辑器的作用。
标签: c# winforms propertygrid