Please help me....
I am stuggling with a drag and drop of picture boxes between panels (panel1 and panel2). On the event where the directory chosen by the user changes, the method UpdateDisplay() is called (below). What is happening is i am traversing thru the directory to display each picture box and upon dragging the picture from panel1 to panel2 an instance of the picturebox is created for each image in the directory.
In simple talk...If i drag and drop an image from one panel to another, it gets copied 5 times to panel2 (because there are 5 images in the directory that panel one points to.
Please help as i need to work this one out urgently. Many thanks in advance experts...
private void UpdateDisplay()
// Clear the current display.
// Row and Col will track the current position where pictures are
// being inserted. They begin at the top-right corner.
int row = border, col = border;
// Iterate through the Images collection, and create PictureBox controls.
foreach (NamedImage image in images)
PictureBox pic = new PictureBox();
pic.Image = image.Image;
pic.Tag = image.FileName;
// pic.Size = new Size(dimension, dimension);
pic.Location = new Point(col, row);
pic.BorderStyle = BorderStyle.FixedSingle;
// StrechImage mode gives us the "thumbnail" ability.
pic.SizeMode = PictureBoxSizeMode.Zoom;
// Display the picture.
panel2.AllowDrop = true;
this.AllowDrop = true;
pic.MouseDown += new MouseEventHandler(FBox1_MouseDown);
// Move to the next column.
col += dimension + spacing;
// Handle the event.
pic.Click += new EventHandler(this.pic_Click);
// Move to next line if no more pictures will fit.
if ((col + dimension + spacing + border) > this.Width)
col = border;
row += dimension + spacing;
panel2.DragDrop += new DragEventHandler(groupBox2_DragDrop);
panel2.DragEnter += new DragEventHandler(groupBox2_DragEnter);
// this.DragEnter += new DragEventHandler(groupBox2_DragEnter);
void FBox1_MouseDown(object sender, MouseEventArgs e)
void groupBox2_DragEnter(object sender, DragEventArgs e)
e.Effect = DragDropEffects.Copy;
void groupBox2_DragDrop(object sender, DragEventArgs e)
if (e.Data.GetData(typeof(Bitmap)) != null)
Bitmap FMap =
PictureBox FBox1 = new PictureBox
FBox1.Image = FMap;
FBox1.SizeMode = PictureBoxSizeMode.Zoom;
FBox1.Dock = DockStyle.Top;