来个问题大家来拍砖:How can I assign my propertyeditor to a component's property
In C# Code:
//*****************************************************************************************************
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;
}
}
}
//*****************************************************************************************************
In Delphi How can I do?
...
published
[EditorAttribute(typeof(MyEditor ),typeof(System.Drawing.Design.UITypeEditor)),
Description('Select your file'),category('MyCategory')]
property MyField :string read FMyField write FMyField ;
...
But it is not work well.