Click here to Skip to main content
15,888,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a form with OpenFileDialog for selecting image and showing it in pictureBox. Until the form is open the user can open and then save the opened image as many times as he wants.But when he secont time open openfiledialog the picture show but the both image show in same location,
I want the picture not show in same location,Please tell me the location of image.
C#
private void button1_Click(object sender, EventArgs e)
{
    PictureBox pic = new PictureBox();
    {
        try{
            OpenFileDialog open = new OpenFileDialog();
            open.Title = "OPen Image";
            // open.Filter = "PNG image (*.png)|*.png|Jpg image (*.jpg)|*.jpg|";
            open.Filter = "JPG Files (*.jpg)|*.jpg|JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|GIF Files (*.gif)|*.gif";
            DialogResult result = open.ShowDialog();
            if (result == DialogResult.OK)
            {
                pic.Image = new Bitmap(open.FileName);
                pic.SizeMode = PictureBoxSizeMode.AutoSize;
                listView1.Controls.Add(pic);
            }   
        }
        catch (Exception ex)
        {
            // Could not load the image - probably related to Windows file system permissions.
            MessageBox.Show("Cannot display the image: " + ex.Message);
        }
    }
}


What I have tried:

Please tell me how to set location in picturebox on running time
Posted
Updated 28-Sep-16 23:07pm
v2
Comments
Suvendu Shekhar Giri 29-Sep-16 3:51am    
Do you just want the second picture to be shown on another PictureBox ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900