Treba ti TypeConverter atribut. Evo i primera:
Code:
using System;
using System.Drawing.Design;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public class NekaKontrola: UserControl
{
private Control m_NekoSvojstvo = new Control();
[Editor(typeof(NekiEditor), typeof(UITypeEditor))]
[TypeConverter(typeof(MojTypeConverter))]
public Control NekoSvojstvo
{
get { return m_NekoSvojstvo; }
set { m_NekoSvojstvo = value; }
}
public NekaKontrola()
{
}
}
public class NekiEditor: UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
if(context != null) {
Form form = new Form();
form.ShowDialog();
form.Dispose();
}
return base.EditValue(context, provider, value);
}
}
public class MojTypeConverter: TypeConverter
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if(value is Control && destinationType == typeof(string)) {
return ((Control)value).Name;
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
}