K,
just i ll write the code..
add a class to your project by name "Output" and add the below code
namespace YourNamespace
{
class Output
{
int row;
int column;
List<Customer> person = new List<Customer>();
public int Row
{
get { return row; }
set { row = value; }
}
public int Column
{
get { return column; }
set { column = value; }
}
public List<Customer> Person
{
get { return person; }
set { person = value; }
}
public void Load(string path)
{
if (File.Exists(path))
{
Output o = ObjectXMLSerializer<Output>.Load(path);
this.row = o.row;
this.column = o.column;
this.person = o.person;
}
}
public void Save(string path)
{
ObjectXMLSerializer<Output>.Save(this, path);
}
}
}
then modify your Form1 (TableLayoutForm) class as follows
namespace MSDNForums
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Output output = new Output();
private void button1_Click(object sender, EventArgs e)
{
output.Person.Clear();
output.Row = int.Parse(rowsTextBox.Text);
output.Column = int.Parse(columnsTextBox.Text);
tableLayoutPanel1.RowCount = int.Parse(rowsTextBox.Text);
tableLayoutPanel1.ColumnCount = int.Parse(columnsTextBox.Text);
for (int col = 0; col < tableLayoutPanel1.ColumnCount; col++)
{
for (int rows = 0; rows < tableLayoutPanel1.RowCount; rows++)
{
Panel p = new Panel();
TextBox tb = new TextBox();
PictureBox picb = new PictureBox();
p.Controls.Add(tb);
p.Controls.Add(picb);
picb.Location = new Point(0, tb.Top + 20);
tableLayoutPanel1.Controls.Add(p, col, rows);
Customer c = new Customer();
c.Index = col * tableLayoutPanel1.RowCount + rows;
}
}
}
private void LoadPerson()
{
output.Load("output.out");
tableLayoutPanel1.Controls.Clear();
foreach (Customer c in output.Person)
{
int rows = c.Index / output.Column;
int col = c.Index % output.Column;
Panel p = new Panel();
TextBox tb = new TextBox();
PictureBox picb = new PictureBox();
p.Controls.Add(tb);
p.Controls.Add(picb);
picb.Location = new Point(0, tb.Top + 20);
tableLayoutPanel1.Controls.Add(p, col, rows);
}
}
private void SavePerson()
{
output.Save("output.out");
}
}
}
you can use SavePerson and LoadPerson function to save and load the file.
If you still didnt get, then better i ll send you the full code :)