I’m trying to add panels to groupbox, the panels will have a backgroundimage.
I have three files, so I should have 3 panels in the groupbox, but 4 panels be displayed with the same photo . I am using the following code:
DirectoryInfo di = new DirectoryInfo(folder);
FileInfo[] rgFiles = di.GetFiles();
Point NewPosition =new Point() ;
foreach (FileInfo fi in rgFiles)
{
Bitmap b = new Bitmap(folder+@"\"+ fi.Name);
Panel p = new Panel();
p.Size = b.Size;
p.BackgroundImage = b;
p.Name = fi.Name;
p.Dock = DockStyle.Top;
control.Controls.Add(p);
}
Any suggestions please.
You are not setting the location of the panels.
I’m guessing the panels are being stacked on top of each other making the top panel the only panel viable.
Panel has a Location property which you can set. You can also dock your panels using the Dock property.
Couple of quick examples:
or