How to set default values ​​for development time value?

According to MSDN ( http://msdn.microsoft.com/en-us/library/system.windows.forms.label.autosize.aspx ) there is a note about the property Label AutoSize:

When added to a form using the constructor, the default value is true. When creating an instance from code, the default value is false.

The question is: how can I override the control Labeland set its value AutoSizefor the development time property for false?

(Update)

And this does not work:

class MyLabel : Label
{
    const bool defaultAutoSize = false;

    public MyLabel()
    {
        AutoSize = defaultAutoSize;
    }

    [DefaultValue(defaultAutoSize)]
    public override bool AutoSize
    {
        get
        {
            return base.AutoSize;
        }
        set
        {
            base.AutoSize = value;
        }
    }
}
+5
source share
3 answers

The control Labelhas an attribute:

[ToolboxItem("System.Windows.Forms.Design.AutoSizeToolboxItem,System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]

AutoSize.

:

[ToolboxItem(true)]
class MyLabel : Label
{
}
+4

. .

public class MyLabel:Label
{
    public MyLabel():base()
    {
        base.AutoSize = false;
    }
}

, . , .

, , , InitLayout, , AutoSize, :

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    [DefaultValue(false)]
    public override bool AutoSize
    {
        get
        {
            return base.AutoSize;
        }
        set
        {
            base.AutoSize = value;
        }
    }

    protected override void InitLayout()
    {
        base.InitLayout();
        base.AutoSize = false;
    }

, , , [Form].Designer.cs :

this.label1 = new MyLabel();// new System.Windows.Forms.Label();

//this.label1.AutoSize = true;

AutoSize, , , , AutoSize

+6

DefaultValueAttribute

:

public class MyLabel : Label
{
    [System.ComponentModel.DefaultValue(false)]
    public override bool AutoSize
    {
        get
        {
            return base.AutoSize;
        }
        set
        {
            base.AutoSize = value;
        }
    }
}

EDIT: . .... .

+2

All Articles