<pre>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Xml.Serialization;
namespace Form1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
List<Label> listLabel = new List<Label>();
private void Form1_Load(object sender, EventArgs e)
{
}
int B = 1;
private void btn_Create_Click_1(object sender, EventArgs e)
{
System.Windows.Forms.Label newLabel = new System.Windows.Forms.Label();
this.Controls.Add(newLabel);
newLabel.Top = B * 28;
newLabel.Left = 50;
newLabel.Text = "DOOR EXIT " + this.B.ToString();
B = B + 1;
newLabel.BorderStyle = BorderStyle.FixedSingle;
newLabel.TextAlign = ContentAlignment.MiddleCenter;
listLabel.Add(newLabel);
}
void SerializeButton()
{
}
void Serialize()
{
StreamWriter sw = new StreamWriter(new FileStream("Setting.TestSave", FileMode.Create));
XmlSerializer seri2 = new XmlSerializer(typeof(int));
seri2.Serialize(sw, listLabel.Count);
foreach (var item in listLabel)
{
SettingInfor info = new SettingInfor();
info.text = item.Text;
info.location = item.Location;
XmlSerializer seri = new XmlSerializer(typeof(SettingInfor));
seri.Serialize(sw, info);
}
sw.Close();
}
void Deserialize()
{
listLabel.Clear();
StreamReader sr = new StreamReader(new FileStream("Setting.TestSave", FileMode.Open));
XmlSerializer seri2 = new XmlSerializer(typeof(int));
for (int i = 0; i<(int)seri2.Deserialize(sr);i++)
{
XmlSerializer seri = new XmlSerializer(typeof(SettingInfor));
SettingInfor info = new SettingInfor();
info = (SettingInfor)seri.Deserialize(sr);
Label newLabel = new Label();
newLabel.Text = info.text;
newLabel.Location = info.location;
listLabel.Add(newLabel);
this.Controls.Add(newLabel);
}
sr.Close();
}
private void btnSave_Click(object sender, EventArgs e)
{
Serialize();
}
private void btnRestore_Click(object sender, EventArgs e)
{
}
}
}
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Form1
{
public class SettingInfor
{
public string text;
public Point location;
}
}