473,466 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Serialization of controls

Does anyone have a good example of how to serialize a controls
properties?
HEre is my example but is does not work

object mObject = this.textBox1;
Debug.WriteLine(mObject.GetType());
XmlSerializer formatter = new XmlSerializer(mObject.GetType());
Stream stream = new FileStream("serialTest.xml",FileMode.Create,
FileAccess.Write,FileShare.None);
formatter.Serialize(stream,mObject);
stream.Close();

John S

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
2 1225
John,

The problem with the XmlSerializer is that it will only save public
properties, and a good number of those properties are other classes that
when serialized, really don't have the correct context. Ultimately, you
can't serialize everything, because things such as a control handle have no
context.

What I would do is create an object that implements
ISerializationSurrogate, so that you can provide serialization semantics
without having to implement it on the control. This way, you can specify
the properties you want to save, and not have to create different classes
which implement ISerializable.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John Sutor" <jo********@cinfin.com> wrote in message
news:uL**************@TK2MSFTNGP10.phx.gbl...
Does anyone have a good example of how to serialize a controls
properties?
HEre is my example but is does not work

object mObject = this.textBox1;
Debug.WriteLine(mObject.GetType());
XmlSerializer formatter = new XmlSerializer(mObject.GetType());
Stream stream = new FileStream("serialTest.xml",FileMode.Create,
FileAccess.Write,FileShare.None);
formatter.Serialize(stream,mObject);
stream.Close();

John S

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2
Nicholas,
I was just trying to figure out how serialization works.
I wanted to create a simple example of using serialization for
something.
If you have a simple sample, I'd be grateful

Thanks,

John
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

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

Similar topics

3
by: scoobydoo | last post by:
Hello, I am trying to implement ICloneable's Clone() function, using Serialization. However, my code causes an exception. I have a class derived from TreeNode called "Node1". In Node1, I...
0
by: S.Sigal | last post by:
Hello: I've been trying to 'organize' the layout of my larger controls by moving variables into instances of subclasses...but it just dawned on me that I might be opening a real can of worms due...
3
by: Shawn Wildermuth | last post by:
I am using a control that creates the inner HTML/XML inside their own ASP.NET tag (e.g. <somelib:somecontrol />). VS.NET 2005 is telling me there is an error that it cannot map these XML inside...
0
by: Jan Warning | last post by:
Hi all, I have an application that displays a large number of custom controls on a form. Now I want to serialize/deserialize the controls. The serialization fails because all controls inherit...
1
by: Jan Warning | last post by:
I have an application that displays custom controls. I want to serialize/deserialize these controls. However, the serialization fails because all controls derive from System.Windows.Forms.Control...
1
by: Lucien Dol | last post by:
Hi all, Can someone help me with this, please? I've got a user control that (amongst other controls) contains a textbox. The textbox has its Anchor property set to "Left, Top, Right", meaning...
5
by: =?Utf-8?B?TmF0aGFuIFdpZWdtYW4=?= | last post by:
Hi, We have an app that uses XML serialization throughout. As everyone probably knows, using XML serialization is not always a good idea in a big project...
6
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
Can a Form be set to Serializable? My App keeps crashing ever time I attempt to serialize the form. I was under the impression that Serialization could be used to easily save all of my data....
0
by: Ronny | last post by:
I'm looking for an example demonstrating a form and its controls (like radio buttons and list boxes)serialization. can someone direct me please? Regards Ronny
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.