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 / .NET Framework / New Users / November 2006

Tip: Looking for answers? Try searching our database.

How to deserialize a SettingsProperty

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Serge BRIC - 14 Nov 2006 07:43 GMT
Hi,

I don't know how to retrieve the default value of user properties.

For instance, I have defined 2 user properties named TheColor and TheFont,
with the type System.Drawing.Color and System.Drawing.Font. I can access
their current values like this:

 dim theColor as System.Drawing.Color = My.MySettings.Default.TheColor
 dim theFont as System.Drawing.Font = My.MySettings.Default.TheColor

I have found in the SettingsProperty objects, the default value in a
serialized form :

 dim theColorProperty as SettingsProperty =
My.MySettings.Default.Properties("TheColor")
 dim theFontProperty as SettingsProperty =
My.MySettings.Default.Properties("TheFont")

 dim defaultColorValue as String = theColorProperty .DefaultValue
 dim defaultFontValue as String = theFontProperty .DefaultValue

Now, how can I build the Color and Font object containing the default values
from these SettingsProperty ? Is there a way to deserialize it ?

Thanks.
Ciaran O''Donnell - 14 Nov 2006 09:04 GMT
Pass the color to Color.FromName() which will give you a color back. Font has
a constructor that takes the name and size (empoints).
e.g

dim defColor as Color = Color.FromName(defaultColorValue)
dim defFont as new Font(defaultFontValue, 12)


Ciaran O'Donnell

> Hi,
>
[quoted text clipped - 22 lines]
>
> Thanks.
Serge BRIC - 14 Nov 2006 09:13 GMT
Thanks for your answer.

I understand that you suggest me to write the deserialization code by
myself. I think I could do that but I was looking for a "standard" way to
deserialize these objects ( Colors, Fonts or anything else). There must be
something like this since application and user properties are serialized and
deserialized by the ApplicationSettingsBase object.

Is there another way to retrieve default values for user properties ?

> Pass the color to Color.FromName() which will give you a color back. Font has
> a constructor that takes the name and size (empoints).
[quoted text clipped - 32 lines]
> >
> > Thanks.
Dave Sexton - 14 Nov 2006 10:22 GMT
Hi,

Try the following:

(Imports System.ComponentModel)

Dim property As SettingsProperty =
My.MySettings.Default.Properties("TheColor")

Dim converter As TypeConverter =
TypeDescriptor.GetConverter(property.PropertyType)

Dim instance As Object = converter.ConvertFromString(property.DefaultValue)

You have to cast property.DefaultValue to System.String, but I can't remember
how to do that in VB.NET - sorry

Signature

Dave Sexton

> Thanks for your answer.
>
[quoted text clipped - 44 lines]
>> >
>> > Thanks.
Serge BRIC - 14 Nov 2006 10:55 GMT
Hi,

That's exactly what I was trying to do. I've been looking for that for many
days.

Thank you so much for your help.

> Hi,
>
[quoted text clipped - 61 lines]
> >> >
> >> > Thanks.

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.