, .:) .
, ... ? I.E., , ( ) ? ... , ,
, , ICloneable, , Clone(). , :
public object Clone() {
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
formatter.Serialize(stream, this);
stream.Seek(0, SeekOrigin.Begin);
return (MyForm) formatter.Deserialize(stream);
}
:
MyForm form2 = form1.Clone() as MyForm;
if (form2 != null) {
}
* *
, SO, . !
* *
, ... , . .
, ISerializable GetObjectData(). GetObjectData (, ), . . :
public partial class MyForm : Form, ISerializable {
public MyForm() {}
public MyForm(SerializationInfo info, StreamingContext context) : base() {
foreach (Control control in Controls) {
control.Text = info.GetString(control.Name);
}
}
public void GetObjectData(SerializationInfo info, StreamingContext context) {
foreach (Control control in Controls) {
info.AddValue(control.Name, control.Text);
}
}
}
, , SerializationInfo . .