Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 22-Dec-11 21:25pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Handle the PictureBox.Click event:
        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[^]
  Permalink  
Comments
IndrajitDasgupat at 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 at 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)



Advertise | Privacy | Mobile
Web04 | 2.8.141022.1 | Last Updated 23 Dec 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100