Hi there. :)
I want to deleting image inside picturebox ( its autogenerated) that selected by mouse click event, So I can delete it with delete key or maybe contextmenu...
GENERATE PICTUREBOX:
private void SHOWIMAGETHUMBNAIL_Click(object sender, EventArgs e) { string theimage = AppDomain.CurrentDomain.BaseDirectory + @"allimages"; string[] images = Directory.GetFiles(theimage, "*.png"); int aa; for (aa = 1; aa < images.Count(); aa++) { PictureBox myPicBox = new PictureBox(); myPicBox.Location = new Point(7, 240); myPicBox.Width = 100; myPicBox.Height = 77; myPicBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; myPicBox.Margin = new Padding(3, 3, 3, 3); myPicBox.Visible = true; myPicBox.Image = new Bitmap(images[aa]); this.flowLayoutPanel1.Controls.Add(myPicBox); //myPicBox.Click += new EventHandler(curPb_Click); //myPicBox.MouseUp += new MouseEventHandler(myPicBox_MouseUp); myPicBox.MouseDown += new MouseEventHandler(myPicBox_MouseDown); myPicBox.MouseLeave += new EventHandler(mmm_Leave); } }
CATCHING EVENT: ( I stuck in here )
//private PictureBox senderAsPictureBox = null; private void mmm_Leave(object sender, EventArgs e) { PictureBox senderAsPictureBox = sender as PictureBox; senderAsPictureBox.BackColor = Color.Empty; } private void myPicBox_MouseDown(object sender, MouseEventArgs e) { PictureBox senderAsPictureBox = sender as PictureBox; MessageBox.Show(senderAsPictureBox.ToString()); senderAsPictureBox.BackColor = Color.AliceBlue; }