具有扩展属性的用户控件

时间:2015-07-03 09:46:27

标签: c# winforms user-controls typeconverter

我正在开发一个用户控件,我需要它有一个自定义扩展属性

public class mycontrol: UserControl
{
    public mycontrol()
    {
        InitializeComponent();
    }

    ExtendedProperty property= new ExtendedProperty();
    [Browsable(true)]
    [TypeConverter(typeof(ExpandableObjectConverter))]
    [RefreshProperties(RefreshProperties.Repaint)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    public ExtendedProperty Thing
    {
        get
        {
            return property;
        }
        set
        {
            property.Text = value.Lbl1Text;
            property.Duration=value.duration;
            property= value;
            this.control1.Text=value.Text;
            this.control2.duration=value.duration;
            this.Refresh();
            Invalidate();
        }
    }
}

[RefreshProperties(RefreshProperties.Repaint)]
[Category("Line")]
[Browsable(true)]
public class ExtendedProperty
{
    public event PropertyChangedEventHandler propertChanged;

    public override string ToString()
    {
        return "";
    }

    string text= "tt";

    [Category("Line")]
    [Browsable(true)]
    [RefreshProperties(RefreshProperties.Repaint)]
    public string Text
    {
        get
        {
            return text;
        }
        set
        {
            text= value;
            propertChanged("text");
        }
    }

    int duration= 5;

    [Category("Line")]
    [Browsable(true)]
    [RefreshProperties(RefreshProperties.Repaint)]
    public string Duration
    {
        get
        {
            return duration;
        }
        set
        {
            duration= value;
            propertChanged("duration");
        }
    }

    void propertChanged(string propertyName)
    {
        if(propertChanged!=null)
        propertChanged(this, new PropertyChangedEventArgs(propertyName));
    }
}

在属性网格中,我可以看到'Thing'和'sub properties(Text,Duration)'但是当我编辑它们时,更改不会反映在GUI上(control1.Text和control2.Duration不会改变)。< / p>

0 个答案:

没有答案