This is my very first program for serialization.
An error occurred when trying to serialize a button control.
public Form1()
{
InitializeComponent();
CheckSerialization();
Button btn = btnSerialized;
}
public void CheckSerialization()
{
Stream write = File.OpenWrite(@"C:\ser.bin");
BinaryFormatter serial = new BinaryFormatter();
serial.Serialize(write, btnSerialized);
write.Close();
}
private void btnSerialized_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream(@"C:\ser.bin",FileMode.Open);
BinaryFormatter bf= new BinaryFormatter();
object obj = bf.Deserialize(fs);
Button button12 = (Button)obj;
button1 = button12;
button1.Location = new Point(0, 0);
}
Type 'System.Windows.Forms.Button' in Assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.**
How do I mark this object as serializable?