不知Winform Control问题在这里是否合适:如何给属性定义属性编辑器(100分)

  • 主题发起人 minercxy
  • 开始时间
M

minercxy

Unregistered / Unconfirmed
GUEST, unregistred user!
在C#中代码如下,一切OK:
//*****************************************************************************************************
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Diagnostics;
using System.Windows.Forms.ComponentModel;
using System.Windows.Forms.Design;

namespace MyControlTest
{
/// <summary>
/// UserControl1
/// </summary>
public class MyControl : System.Windows.Forms.Control
{
private System.ComponentModel.Container components;
private string myfield = "";

public MyControl()
{
InitializeComponent();
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}


void InitializeComponent ()
{
this.components = new System.ComponentModel.Container ();
}

//PropertyEditor Assign
[
Category("Mycategory"),
Editor(typeof(MyEditor), typeof(UITypeEditor)),
DefaultValue("")
]
public string MyField
{
get
{
return myfield;
}
set
{
myfield = value;
}
}

}


//Define My property Editor
public class MyEditor : System.Drawing.Design.UITypeEditor
{

public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
//Show my dialog
value = "";
return value;
}

public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}

}

}
//*****************************************************************************************************
然而在Delphi中:
...
published
[EditorAttribute(typeof(MyEditor ),typeof(System.Drawing.Design.UITypeEditor)),
Description('Select your file'),category('MyCategory')]
property MyField :string read FMyField write FMyField ;
...
编译,控件加载均无问题,只是MyField属性仍然无法使用自定定义的属性编辑器MyEditor,
请问诸位前辈,Delphi中如何为WinForm Control 属性定义自己的属性编辑器?
难道仍然要使用VCL中的方法:RegisterPropertyEditor?
 
www.source520.com 再次更新近3万代码,全部免费免注册狂下载
 
顶部