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);}How do I mark this object as serializable? 解决方案 Find the line that looks like public partial class Form1 : Form.Right above it, place [Serializable]. That marks your class for serialization.You will need to control your own serialization however, since as noted below, UI objects do not serialize. For that, look at the ISerializable interface.More information about SerializableAttribute is here. 这篇关于将WinForms Button标记为可序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-27 10:41