I'm developing a Windows forms application which captures screenshots and create documents out of them.
What my form design looks like is as the snapshots are captured, a picture box with a thumbnail size will be created and added to the form dynamically. Whenever this picture box is clicked, an enlarged version of the image is displayed in another picture box. I've done all of this stuff.
Here's what I've done to generate picture boxes of thumbnail sizes and when they're clicked images enlarge.
private void FillImagePanel(Bitmap imgBmp)
{
PictureBox tempPictureBox = new PictureBox();
tempPictureBox.Tag = imgBmp;
//generates a thumbnail image of specified size
tempPictureBox.Image = imgBmp.GetThumbnailImage(100, 100,
new Image.GetThumbnailImageAbort(ThumbnailCallback),
IntPtr.Zero);
tempPictureBox.Size = new System.Drawing.Size(100, 100);
tempPictureBox.Cursor = Cursors.Hand;
tempPictureBox.Click += new EventHandler(this.tempPictureBox_Click);
ImageFlowLayoutPanel.Controls.Add(tempPictureBox);
}
//This click event will be used to display the enlarged images
private void tempPictureBox_Click(object sender, EventArgs e)
{
Bitmap reSizedImage = new Bitmap((Bitmap)((PictureBox)sender).Tag,
new System.Drawing.Size(600,400));
PreviewPictureBox.Image = reSizedImage;
}
Now I would also like to add the ability to delete the images snapped. I'm having trouble in doing this task.
I've set the form's KeyPreview property to True and added the KeyDown event to handle the delete key press.
priavte void SnapperForm_KeyDown(Object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Delete)
{
//write code here to delete the thumbnail sized picture box
}
}
There will be many picture boxes generated dynamically and added to the form. My question is how do I know which picture box the user has chosen to remove from the form? How do I wire up the above event whenever an image is selected and Delete key is pressed by user?
Thanks in advance

New Topic/Question
Reply




MultiQuote




|