I have a class library with a custom control in it:
using System.ComponentModel;
using System.Windows.Forms;
namespace ClassLibrary1
{
public sealed class CustomLabel : Label
{
[DefaultValue(false), Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override bool AutoSize
{
get => base.AutoSize;
set => base.AutoSize = value;
}
public CustomLabel()
{
AutoSize = false;
}
}
}
Notice that AutoSize
is set to false in both the constructor and the designer attribute on the overridden method.
I have a winforms project where I want to use the control. I drag/drop it from the toolbox, but it doesn't have AutoSize
set to false:
If I save and close the form and then re-open it, now it's set correctly:
How can I make it respect the property value when first dropped on the form?