473,396 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to save a component state?

Hello,

Is there an easy way in C# to save a component (control) state (example.
save all the property values from a button control) to a file (xml) ?

Kind regards;

Peter.
Nov 15 '05 #1
7 2879
UI objects generally don't serialize well. The Memento pattern is often used
to good effect.

http://www.ondotnet.com/pub/a/dotnet...9/memento.html

--
Bob Powell [MVP]
C#, System.Drawing

The October edition of Well Formed is now available.
Find out how to use DirectX in a Windows Forms control
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Peter Verburgh" <pe*****@skynet.be> wrote in message
news:3f**********************@reader0.news.skynet. be...
Hello,

Is there an easy way in C# to save a component (control) state (example.
save all the property values from a button control) to a file (xml) ?

Kind regards;

Peter.

Nov 15 '05 #2
Serializer and Deserializer, these are used for persistant storage ie.,
anything public in the type and subtypes (if not set to ignore in the
attributes) are written to XML.
"Peter Verburgh" <pe*****@skynet.be> wrote in message
news:3f**********************@reader0.news.skynet. be...
Hello,

Is there an easy way in C# to save a component (control) state (example.
save all the property values from a button control) to a file (xml) ?

Kind regards;

Peter.

Nov 15 '05 #3
So you just create a new object and pick off what you want to persist then
serialize that momento object.

Why they just dont say that at the start of the pattern examples is beyond
me, they just like to make it look fancy.

If you have control of the object you can always mark some properties as not
to be serialized.

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
UI objects generally don't serialize well. The Memento pattern is often used to good effect.

http://www.ondotnet.com/pub/a/dotnet...9/memento.html

--
Bob Powell [MVP]
C#, System.Drawing

The October edition of Well Formed is now available.
Find out how to use DirectX in a Windows Forms control
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Peter Verburgh" <pe*****@skynet.be> wrote in message
news:3f**********************@reader0.news.skynet. be...
Hello,

Is there an easy way in C# to save a component (control) state (example.
save all the property values from a button control) to a file (xml) ?

Kind regards;

Peter.


Nov 15 '05 #4
> Why they just dont say that at the start of the pattern examples is beyond
me, they just like to make it look fancy.
;-)

The memento pattern is great for classes that hold references to parents or
other items in a linked list or stuff that's not at-all serializable. Many's
the time I've tried to serialize something and discovered that it holds a
reference to some sealed class somewhere. It enforces the rule of knowing
exactly what it is you're serializing and why, moreover it prevents you from
having to do stupid stuff like walk a tree of objects removing all the
things that cannot be serialized, doing the save and then walking the tree
putting all the stuff that was removed back again.

--
Bob Powell [MVP]
C#, System.Drawing

The October edition of Well Formed is now available.
Find out how to use DirectX in a Windows Forms control
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

<di********@discussion.microsoft.com> wrote in message
news:Ok**************@TK2MSFTNGP09.phx.gbl... So you just create a new object and pick off what you want to persist then
serialize that momento object.

Why they just dont say that at the start of the pattern examples is beyond
me, they just like to make it look fancy.

If you have control of the object you can always mark some properties as not to be serialized.

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
UI objects generally don't serialize well. The Memento pattern is often

used
to good effect.

http://www.ondotnet.com/pub/a/dotnet...9/memento.html

--
Bob Powell [MVP]
C#, System.Drawing

The October edition of Well Formed is now available.
Find out how to use DirectX in a Windows Forms control
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Peter Verburgh" <pe*****@skynet.be> wrote in message
news:3f**********************@reader0.news.skynet. be...
Hello,

Is there an easy way in C# to save a component (control) state (example. save all the property values from a button control) to a file (xml) ?

Kind regards;

Peter.



Nov 15 '05 #5
Hi,

A slightly tongue-in-cheek look at Design patterns.

Design Pattersn are the result of some people noticing that certain -
guess what ;-) - patterns keep appearing in their code. They decided to
classify and catalogue - and thus Design Patterns became formalised and a
new discipline was born.

<Every single programmer> uses patterns - coding habits/techniques. Read
enough about Design Patterns and you'll find that a name has been given to
something you've already been doing, perhaps for years. (How many unrealised
Singleton Patterns must there be out there).

Often, giving a name to a pattern (and hence making it a <Design Pattern>)
will enable thinking to become clarified. It certainly enhances communication
between those who are 'in the know' - as does all jargon - though the downside
is that, of course, outsiders get excluded.

Another advantage is that a pattern, once formally designated, is open to
scrutiny, experimentation, enhancement, etc and there is somewhere to 'hang
the results' so that other people can benefit.

Many patterns are obvious once you have seen the code behind the name -
"yeah, ok, so they have a name for it". Others are a revelation "Hey! I can
use this!!". Others are in between - giving a new angle on something, a hint
or tip, an improvement. "Hmm, that looks a bit better than mine".

Some Design Patterns have not been catalogued, but are nevertheless widely
implemented. These tend to have a wide number of variations making
classification difficult, but would come under such headings as Plate of
Spaghetti, Can of Worms, Monolithic Block, Repetitious Garbage and the like.

In these days of OOP there are large numbers of classes following the
Grumpy Tiger Pattern - nobody dares look at it, let alone go near it!

Regards,
Fergus

Nov 15 '05 #6
Jj
make it serializable and serialize it.

Jianjun
"Peter Verburgh" <pe*****@skynet.be> wrote in message
news:3f**********************@reader0.news.skynet. be...
Hello,

Is there an easy way in C# to save a component (control) state (example.
save all the property values from a button control) to a file (xml) ?

Kind regards;

Peter.

Nov 15 '05 #7
Which beget antipatterns :).

Regards,
Jeff
Some Design Patterns have not been catalogued, but are nevertheless

widely implemented. These tend to have a wide number of variations
making classification difficult, but would come under such headings as
Plate of Spaghetti, Can of Worms, Monolithic Block, Repetitious Garbage
and the like.<
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: John J. Hughes II | last post by:
I need to save a DWORD to the sql server, the below posts an error, any suggestions on what I am doing wrong. I have the column in the sql server defined as an int since unsigned int is not valid....
12
by: John | last post by:
Hi Is there a way to save the layout of controls (position, size, visibility, appearance etc.) to a file (xml?) and also be able to load the layout from a file? The idea being that these file...
0
by: fish | last post by:
Hi, I have a VB.net application that will save attachments to a directory on my local pc. I need to run this component on our exchange 2003 server and also save the attachments to a local DIR. ...
8
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box...
10
by: Henok Girma | last post by:
Hello Gurus, I want to save the state of an unbound DataGridView on my Windows Form application to an XML file so i can later load it back.. Basically, on my form I have a DataGridView, it's got...
1
by: Irene | last post by:
Hello all! I'm creating a web site in ASP.NET (VB.NET). One of the requirements was to allow users to create orders going through several steps. A must have is to have an option to save the work...
14
by: fdu.xiaojf | last post by:
Hi, I have a program which will continue to run for several days. When it is running, I can't do anything except waiting because it takes over most of the CUP time. Is it possible that the...
1
by: Rameel | last post by:
Friends, I'm probably being more critical with VB.Net Windows application. I have Developed VisualStudio 20005 VB.Net Windows application how willl i be able to save a specific record into my...
14
by: squrel | last post by:
Hello everyone, I m using some button using toolbar such as Add,Save,View,.... my save button is not working.... it doesnt give me any error but does not save to my database.... or showing in my...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.