I have tried out this code. This ignores the button altogether and seems to work just fine:
using System;
using System.IO;
using System.Xml.Serialization;
using System.Windows.Forms;
namespace SerialTest
{
// This is the class that will be serialized.
public class Group
{
[XmlIgnoreAttribute]
public System.Windows.Forms.Button myButton;
// a group name or something
public string GroupName;
// a comment of some sort...
public string Comment;
public void SerializeObject(string filename)
{
// Create an XmlSerializer instance.
XmlSerializer xSer = new XmlSerializer(typeof(Group));
// Writing the file requires a TextWriter.
TextWriter writer = new StreamWriter(filename);
// Serialize the object and close the TextWriter.
xSer.Serialize(writer, this);
writer.Close();
}
}
}
To run this the example I used was a form with a button and the following code on the OnClick
event:
Group a = new Group();
a.Comment="A sample comment";
a.GroupName="A sample group name";
a.myButton = this.button1;
a.SerializeObject("c:\\test.xml");
That worked.
- Eitsop What we do not understand we do not possess. - Goethe.