Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I just completed a program to serialize image and text and save it in a XML file.

However, I was trying to extend the concept further. My WinForm has a TableLayoutPanel over it in which each cell has a different image.

Although I am able to save the index i.e row and column number of the picture but I have become really confused about saving picture and its corresponding PictureTag in the same XML file.

I have tried this in a sample here . http://cid-7cfad5624f27df6f.office.live.com/self.aspx/.Public/WindowsFormsApplication2.zip?sa=699375267[^]

The problem is to save the pictures and their picture tags in the TableLayout along with their index so that when it is loaded it is retrieved in the same way in which it was saved.
Yes, I am confused! x-| totally HELP
Posted
Updated 15-Oct-10 22:00pm
v2

Hi,
You have to add Images to Output class in order to Serialize those picrures.
Change the SavePerson() function in the MainWindow Form

C#
private void SavePerson()
        {
            for (int i = 0; i < tableLayoutPanel1.Controls.Count; i++)
            {
                Panel p = tableLayoutPanel1.Controls[i] as Panel;
                Image image = (p.Controls[0] as PictureBox).Image;
                Customer c = new Customer();
                c.Index = i;
                c.Picture = (Bitmap)image;
                output.Person.Add(c);
            }
            output.Save(AppDomain.CurrentDomain.BaseDirectory + "output.out");
        }



also change the LoadPerson() function in the same form as follows

C#
private void LoadPerson()
        {
            //Load code
            output.Load(AppDomain.CurrentDomain.BaseDirectory + "output.out");
                tableLayoutPanel1.Controls.Clear();
                tableLayoutPanel1.ColumnCount = output.Column;
                tableLayoutPanel1.RowCount = output.Row;
                foreach (Customer c in output.Person)
                {
                    int rows = c.Index / output.Column;
                    int col = c.Index % output.Column;
                    Panel p = new Panel();
                    //p.Dock = DockStyle.Fill;
                    PictureBox picb = new PictureBox();
                    //Picture Box properties
                    picb.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
                    picb.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
                    picb.BackColor = Color.White;
                    picb.Dock = DockStyle.Fill;
                    picb.Image = c.Picture;
                    //Set the label properties
                    //Label lb = new Label();
                    //lb.BackColor = Color.White;
                    //lb.Size = new Size(88, 15);
                    //p.Controls.Add(lb);
                    p.Controls.Add(picb);
                    //lb.Location = new Point(panel1.Left + 1, panel1.Top + 1);
                    //picb.Location = new Point(0, lb.Top + 20);
                    picb.MouseClick += pb_Click;
                    picb.MouseLeave += pb_Leave;
                    tableLayoutPanel1.Controls.Add(p, col, rows);
                }
        }



I think this will work..

There are other mistakes like, Border setting, back color...etc
I think you can do all those things.
I just concentrated on Serialize and Deserialize of image files

All the best..:thumbsup:
 
Share this answer
 
Comments
optimus_prime1 16-Oct-10 3:15am    
Many thanks for your help!
I had further question regarding storing a .wav in the same XML file.
A picture box can have a Tag associated with it or a 'Recorded .wav'.
The recorded wav comes from Form2.
If the user records the sound and even gives the tag to the picture, then preference is given to the saving/playing the sound.
How do I save and load this wav in the XML file?
Thanks!
optimus_prime1 16-Oct-10 3:44am    
Although, I have set the SizeMode if Picture to Zoom, but still the loaded pictures come in size smaller than the size they were saved?
What am I doing wrong?
optimus_prime1 16-Oct-10 4:06am    
How do we store color in the XML file.
I think color is not serializable and we have to make the Color class serializable but how how do I do this in this sample.
Thanks!
Color class consists of segment R G and B
the combination of these segments make a color
so you can save the segment value inorder to store the color.
 
Share this answer
 
v2
Comments
optimus_prime1 16-Oct-10 11:56am    
And could you please help in the other two problems too?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900