Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / October 2004

Tip: Looking for answers? Try searching our database.

Problems with codedom serialization

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrea Gelati \(Protocube Team\) - 16 Oct 2004 16:23 GMT
Hi,

Actually have try to redefine the BackColor and ForeColor of the Control
class using the key 'new' with the DesignerSerializationVisibility.Content
attrubute. Well, the desinger not serialize this property.

Any ideas about?

Thank's in advance!.

-- Andrea Gelati
Protocube Team
www.protocube.com
Mick Doherty - 16 Oct 2004 18:05 GMT
\\\
private Color faceColor = Color.Empty;

[AmbientValue(typeof(Color),"Empty")]
public new Color BackColor
{
   get
   {
       if (faceColor == Color.Empty && Parent != null)
           return Parent.BackColor;
       return faceColor;
   }
   set
   {
       faceColor = value;
       this.Invalidate();
   }
}
private bool ShouldSerializeBackColor()
{
   return faceColor != Color.Empty;
}
private new void ResetBackColor()
{
   faceColor = Color.Empty;
}
///

The above property serializes just fine without the
DesignerSerializationVisibility attribute.

base.BackColor and this.BackColor will return different results, so just
watch which one you ask for.

Signature

Mick Doherty
http://dotnetrix.co.uk/nothing.html

> Hi,
>
[quoted text clipped - 9 lines]
> Protocube Team
> www.protocube.com
Andrea Gelati \(Protocube Team\) - 16 Oct 2004 18:22 GMT
Hi Mick,

Well, now run as well but for me is clear why.

Is possible explains me and at the group when is possible use the
DesignerSerializationVisibility and the SouldSerializeMethod ways?

I think the second the have necessity to redefine a base.Method?

Thank's in advance,

-- Andrea Gelati

> \\\
> private Color faceColor = Color.Empty;
[quoted text clipped - 49 lines]
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.775 / Virus Database: 522 - Release Date: 08/10/2004
Frank Hileman - 16 Oct 2004 23:13 GMT
DesignerSerializationVisibility is to specify if something should be
serialized at all, or if set to "Content", it means you should serialize the
things "inside" and not the thing itself. For example, the Controls
collection would be Content, as the collection itself is not serialized, but
the objects in it are.

ShouldSerialize (and Reset if you want to be friendly) are needed if the
"default" value cannot be expressed as a constant, either because it is an
object reference, or because it is determined dynamically.

There are articles in the MSDN discussing these.

Regards,
Frank Hileman

check out VG.net: www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio .NET graphics editor

> Hi Mick,
>
[quoted text clipped - 8 lines]
>
> -- Andrea Gelati
Mick Doherty - 16 Oct 2004 23:48 GMT
We used the ShouldSerialize method because we wanted Ambient property
behaviour. In other words we want our BackColor property to return the
parent controls BackColor if we do not specify a color. We supplied the
AmbientValue attribute to the property for proper behaviour in the IDE.
Comment out the attribute, rebuild the control and change the property in
the IDE. You should visually see the result in your control. Now right click
on the property and choose Reset. The property will reset to the parent's
BackColor, but you will see no Visual effect of this in your control until
it is invalidated. Now uncomment the attribute and repeat these same steps
and you should see the Control is invalidated upon Reset.

In the following example we do not use the ShouldSerialize method but the
property is serialized if it is not at it's default value of
SystemColors.Control. If we do not supply the DefaultValue attribute then
the property will always be serialized.
Also note that this property does not follow the Parents Background property
since we have used a static value to define the default value.

\\\
private Color faceColor = SystemColors.Control;

[DefaultValue(typeof(Color),"Control")]
public new Color BackColor
{
   get
   {
       return faceColor;
   }
   set
   {
       faceColor = value;
       this.Invalidate();
   }
}
///

Use the DesignerSerializationVisibility attribute to get the code generator
to serialize your property if it returns a  type that does not have a
serializer.

Signature

Mick Doherty
http://dotnetrix.co.uk/nothing.html

> Hi Mick,
>
[quoted text clipped - 62 lines]
>> Checked by AVG anti-virus system (http://www.grisoft.com).
>> Version: 6.0.775 / Virus Database: 522 - Release Date: 08/10/2004

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.