Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All
I am doing C# windows project where I have to upload a image in a picture box through clicking the picture box event no button event

Can any one please help code for the picture box through which I can upload Picture in picture box event


Thanks & Regards
Indrajit Dasgupta
Posted

1 solution

Handle the PictureBox.Click event:
C#
private void pictureBox1_Click(object sender, EventArgs e)
    {
    PictureBox p = sender as PictureBox;
    if (p != null)
        {
        OpenFileDialog ofd = new OpenFileDialog();
        if (ofd.ShowDialog() == DialogResult.OK)
            {
            p.Image = Image.FromFile(ofd.FileName);
            }
        }
    }
You may want to restrict the files in the dialog to just Image files, use the Filter property for that.
There is a Tip here which tells you how to get the images-only filter: A FileDialog.Filter generator for all supported images[^]
 
Share this answer
 
Comments
IndrajitDasgupat 23-Dec-11 4:35am    
Yes It is working fine but how to make the same size of every image to that picture box
OriginalGriff 23-Dec-11 5:05am    
Set the PictureBox.SizeMode to PictureBoxSizeMode.StretchImage

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