views:

46

answers:

2

Hi, I have created pictureboxes dynamically in windows forms Application... its working well... now i have to generate label boxes dynamically and that label boxes will display in bottom of the each picture box and that have to display the corressponding picturebox name... how shall i do this? Give me the solution of this...

Thanks In Advance... And My coding Is here..

           int Left = this.Left+200;
           int Top = this.Top;

           for(int i=0;i<Num_Picbox;i++)
           {
           shapes[i] = new PictureBox();
           shapes[i].Location = new Point(Left,Top);
           Left += 200;
           Top += i + 0;

           shapes[i].Size = new Size(160,160);
           shapes[i].BackColor = Color.Black;
           shapes[i].Visible = true;
           shapes[i].Name = i.ToString();
           shapes[i].BorderStyle = BorderStyle.FixedSingle;

           flowLayoutPanel1.Controls.Add(shapes[i]);
           flowLayoutPanel1.WrapContents = true;
           shapes[i].Click += new EventHandler(PictureBox_Click);
          }
+2  A: 

I think the best way would be to create a custom user control with picturebox and a label laid out the way you want then add them dynamically to the flowlayoutpanel. making shapes[] an array of the custom control type.

sadboy
+1  A: 

Create a panel for each picture that contains a label docked to Bottom and your picture box docked to Fill. Add this panel to the flow layout panel instead of your picture box. Make sure you add your picture box to the panel's Controls collection first to ensure that the docking works as expected.

shapes[i].Dock = DockStyle.Fill;
flowLayoutPanel1.Controls.Add(
    new Panel {
        Controls = {
            shapes[i],
            new Label {
                Dock = DockStyle.Bottom,
                Text = i.ToString()
            }
        }
    });
Nathan Baulch
Thank you So Much!!! Its Working... Thanks for your Nice way to Answer...Its Clearly understood by me...
Suryakavitha
but how can i display image in that picturebox...
Suryakavitha