Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Wed, 7 May 2008 16:38:23 -0700,    group: microsoft.public.dotnet.framework.windowsforms.designtime        back       


Changing the designer DefaultValue for a Property within a Property (Nested Property)   
Hi,

I have an inherited control that derives from a control from a vendor. 
Let's call the vendor control VC and my inherited control myVC.

VC has a property Calendar which itself has various other properties such as 
BackColor.  So to access in code from myVC i would use 
this.Calendar.BackColor syntax.

The vendor has changed the default value for Calendar.BackColor property and 
I want to be able to override the default value with the prior default in 
myVC.

I'm not sure how to do this.  I was looking at the ShouldSerializeXXXX and 
ResetXXXX methods but I don't know how to make them work with nested 
properties.

I tried this could but it did not work.

  private bool ShouldSerializeCalendar_BackColor()
  {
   return Calendar.BackColor != SystemColors.Window;
  }

  private void ResetCalendar_BackColor()
  {
   Calendar.BackColor = SystemColors.Window;
  }

Is this possible and if so how would one go about implementing in the 
derived class?
--
Gregg Walker
date: Wed, 7 May 2008 16:38:23 -0700   author:   Gregg Walker am

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])

Re: Changing the designer DefaultValue for a Property within a Property (Nested Property)   
Hi Linda,

Thanks for taking the time to provide the sample code.  Unfortunately the 
Calendar property is not virtual and therefore not overrideable.

The closest I have been able to get is with a surrogate property in MyVC 
derived control.  Here's the code...

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MyCalendar
{
 public partial class MyVC : C1.Win.C1Input.C1DateEdit
 {
  public MyVC()
  {
   InitializeComponent();

   Calendar.BackColor = SystemColors.Window;
   Calendar.ForeColor = SystemColors.WindowText;
  }

  // Surrogate Property for Calendar.BackColor
  [Browsable(true)]
  [Description("Calendar Background Color")]
  [RefreshProperties(RefreshProperties.All)]
  [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  public Color CalendarBackColor
  {
   get
   {
    return Calendar.BackColor;
   }

   set
   {
    Calendar.BackColor = value;
   }
  }

  private bool ShouldSerializeCalendarBackColor()
  {
   return Calendar.BackColor != SystemColors.Window;
  }

  private void ResetCalendarBackColor()
  {
   Calendar.BackColor = SystemColors.Window;
  }

  // Surrogate Property for Calendar.ForeColor
  [Browsable(true)]
  [Description("Calendar Foreground Color")]
  [RefreshProperties(RefreshProperties.All)]
  [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  public Color CalendarForeColor
  {
   get
   {
    return Calendar.ForeColor;
   }

   set
   {
    Calendar.ForeColor = value;
   }
  }

  private bool ShouldSerializeCalendarForeColor()
  {
   return Calendar.ForeColor != SystemColors.WindowText;
  }

  private void ResetCalendarForeColor()
  {
   Calendar.ForeColor = SystemColors.WindowText;
  }
 }
}

This works somewhat but now I've got two places I can set the Calendar 
BackColor (1=Calendar.BackColor 2=CalendarBackColor) and each with its own 
default.  Also even when the CalendarBackColor is set to the default value 
code is still generated in the designer class to set the default values in 
the Calendar.BackColor property.

There's got to be an easier way to set the default value for a nested 
property.  Do you have any other suggestions?
--
Gregg Walker
date: Thu, 8 May 2008 10:30:40 -0700   author:   Gregg Walker am

Re: Changing the designer DefaultValue for a Property within a Property (Nested Property)   
Hi Gregg,

Thank you for your reply!

You have mentioned "The vendor has changed the default value for 
Calendar.BackColor property" in your first message. How did the vendor 
change the default value for the Calendar.BackColor property within the VC 
class?

If the Calendar property in the VC class is not overridable, I don't think 
we can change the default value of the nested properties of the Calendar 
property from within the MyVC class.

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.

This posting is provided "AS IS" with no warranties, and confers no rights.
date: Fri, 09 May 2008 05:58:56 GMT   author:   (Linda Liu[MSFT])

Re: Changing the designer DefaultValue for a Property within a Property (Nested Property)   
Hi Linda,

Thanks for your help with this issue.

> You have mentioned "The vendor has changed the default value for
> Calendar.BackColor property" in your first message. How did the vendor
> change the default value for the Calendar.BackColor property within the VC
> class?

The Calendar property is a DateEditMonthCalendar class which is part of the 
vendor components package.  They changed the default value of the BackColor 
property to SystemColors.Control from SystemColors.Window in the 
DateEditMonthCalendar class in their latest revision.

> If the Calendar property in the VC class is not overridable, I don't think
> we can change the default value of the nested properties of the Calendar
> property from within the MyVC class.

That's too bad there's not a way to override the default values for nested 
properties in a derived class without overriding the parent property itself. 
It would be nice if ShouldSerialize and Reset could be modified to work with 
nested properties.  I would appreciate it if you could pass this on as a 
request for future consideration.

Thanks again for your help.
--
Gregg Walker
date: Fri, 9 May 2008 09:19:36 -0700   author:   Gregg Walker am

Re: Changing the designer DefaultValue for a Property within a Property (Nested Property)   
Hi Gregg,

Thank you for your reply!

I understand your concern. Although there's no way to override the default 
value of the BackColor property of the Calender property in the MyVC class 
if the Calendar property defined in the VC class is not overridable, we can 
change the initial value of the Calender.BackColor property in the MyVC 
class's constructor.

Ok, no problem. I will pass your feedback to our product team for future 
consideration.

If you have any other questions in the future, please don't hesitate to 
contact us. It's always our pleasure to be of assistance!

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.

This posting is provided "AS IS" with no warranties, and confers no rights.
date: Wed, 14 May 2008 05:56:25 GMT   author:   (Linda Liu[MSFT])

Re: Changing the designer DefaultValue for a Property within a Property (Nested Property)   
You should be able to shadow the property "new" in C# or "shadows" in VB.

Then change the attributes as you like.

Schneider

"Linda Liu[MSFT]"  wrote in message 
news:QeFZGdYtIHA.1788@TK2MSFTNGHUB02.phx.gbl...
> Hi Gregg,
>
> Thank you for your reply!
>
> I understand your concern. Although there's no way to override the default
> value of the BackColor property of the Calender property in the MyVC class
> if the Calendar property defined in the VC class is not overridable, we 
> can
> change the initial value of the Calender.BackColor property in the MyVC
> class's constructor.
>
> Ok, no problem. I will pass your feedback to our product team for future
> consideration.
>
> If you have any other questions in the future, please don't hesitate to
> contact us. It's always our pleasure to be of assistance!
>
> 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.
>
> This posting is provided "AS IS" with no warranties, and confers no 
> rights.
>
>
date: Wed, 23 Jul 2008 16:13:41 -0500   author:   eschneider am

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us