C
Charlie
Imagine I subclass Panel into MyPanel and set a few property values to my
own defaults as shown below. Eg. I set BackColor to by LightYellow.
When I add MyPanel to a form, it will write the non-default property values
into the InitializeComponent of the form. So it will explicitily set
myPanel1.BackColor = Color.LightYellow. If I later change the MyPanel
BackColor default from LightYellow to LightRed, it will not reflect this in
my form since the panel on the form is explicitely set to LightYellow.
I hope that makes sense.
Now, I know I can override BackColor and use the [DefaultValue ... ] option
to define new defaults in MyPanel, but if I'm modifying a dozen properties
then do I really need to this for every modified property?
public class MyPanel : Panel
{
public MyPanel()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// MyPanel
//
this.AutoSize = true;
this.AutoSizeMode =
System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.BackColor = System.Drawing.Color.LightYellow;
this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.ResumeLayout(false);
}
}
--Charlie
own defaults as shown below. Eg. I set BackColor to by LightYellow.
When I add MyPanel to a form, it will write the non-default property values
into the InitializeComponent of the form. So it will explicitily set
myPanel1.BackColor = Color.LightYellow. If I later change the MyPanel
BackColor default from LightYellow to LightRed, it will not reflect this in
my form since the panel on the form is explicitely set to LightYellow.
I hope that makes sense.
Now, I know I can override BackColor and use the [DefaultValue ... ] option
to define new defaults in MyPanel, but if I'm modifying a dozen properties
then do I really need to this for every modified property?
public class MyPanel : Panel
{
public MyPanel()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// MyPanel
//
this.AutoSize = true;
this.AutoSizeMode =
System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.BackColor = System.Drawing.Color.LightYellow;
this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.ResumeLayout(false);
}
}
--Charlie