|
|
|
date: Wed, 7 May 2008 16:38:23 -0700,
group: microsoft.public.dotnet.framework.windowsforms.designtime
back
RE: Changing the designer DefaultValue for a Property within a Property (Nested Property)
Hi Gregg,
Firstly, to set a default value for a property of a class, we set the value
of this property in the class's constructor first and then use the
DefaultValueAttribute on the property to specify the default value. In the
Properties window, any values other than the default value of the property
will shown in a bold font.
Secondly, if a property is overriable, we can derive from the class and
override the property. Change the initial value of the property in the
derived class's constructor and adorn the DefaultAttribute on the override
property to specify the new default value so as to change the default value
of the property.
To your question, if the Calendar property is overriable in the VC class,
you can add a new property in the MyVC class to hide the Calendar property.
The following is a sample to do this.
public partial class VC : UserControl
{
public VC()
{
InitializeComponent();
calendar = new MonthCalendar();
}
private MonthCalendar calendar;
[TypeConverter(typeof(ExpandableObjectConverter)),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public virtual MonthCalendar Calendar
{
get { return calendar; }
set { calendar = value; }
}
}
public class DerivedType:MonthCalendar
{
public DerivedType()
{
BackColor = Color.Red;
}
[DefaultValue(typeof(Color),"Red")]
public override Color BackColor
{
get
{
return base.BackColor;
}
set
{
base.BackColor = value;
}
}
}
public partial class MyVC : VC
{
public MyVC()
{
InitializeComponent();
calendar = new DerivedType();
}
private DerivedType calendar;
[TypeConverter(typeof(ExpandableObjectConverter)),DesignerSerializationVisib
ility(DesignerSerializationVisibility.Content)]
public new DerivedType Calendar
{
get { return calendar; }
set { calendar = value; }
}
}
At last, the ShouldSerialize*** method is used by designer to determine
whether the specified property should be serialized in the
InitializeComponent method. The Reset*** method is used by the designer to
reset the property to the default value in the Properties window. The
DefaultValueAttribute does the all the work these two methods do.
Hope this helps.
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
date: Thu, 08 May 2008 11:16:50 GMT
author: (Linda Liu[MSFT])
|
|