473,671 Members | 2,311 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2894
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.sk ynet.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.sk ynet.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@_spamkille r_bobpowell.net > wrote in message
news:uP******** ******@TK2MSFTN GP09.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.sk ynet.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********@dis cussion.microso ft.com> wrote in message
news:Ok******** ******@TK2MSFTN GP09.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@_spamkille r_bobpowell.net > wrote in message
news:uP******** ******@TK2MSFTN GP09.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.sk ynet.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.sk ynet.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
4137
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. Also trying to avoid setting it to a bigint in the server. Casting an int to an uint use to work in C++. System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(...); cn.Open()
12
2295
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 scan serve as templates for different clients who may have different preferences. Is someone has worked with this and can post some code examples then that would be highly appreciated.
0
2876
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. When the component is run on the exchange 2003 server a wizard gui is automatically started which wants to install Outlook 2003. The component is using mapi to access the default inbox. What do i need to do to convert this component to run on...
8
3661
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 and save it to a file. This step is not to hard however the contents of the textarea is mostly latex source so it contains just about every special character you can imagine. My question is this, how do I save an exact copy of the textarea...
10
39481
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 some DataGridViewTextBoxCell, DataGridViewComboBoxCell etc, i want to export all that to XML.. Any help is greatly appreciated.
1
3035
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 in any phase (any step) and to be able to continue later. My idea was to create several pages as steps (no, wizard control is not suitable for several reasons) and to allow users to save any step to the database, that is, a ViewState of the...
14
3438
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 program can save all running data to a file when I want it to stop, and can reload the data and continue to run from where it stops when the computer is free ?
1
3722
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 database file throu GUI Save Record button? As i write the comand as foloow but it is not inserting the new record in to the Access Database. Public Function Open_Connection() As Boolean Try Select Case...
14
3673
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 gird... Plz Help here is my code for save button Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button) On Error GoTo ChkErr If Button.Index = 1 Then Mode = "Add" Call AddMode Call...
0
8473
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8390
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8911
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8819
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8667
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7428
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4402
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2808
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.