Click here to Skip to main content
15,899,475 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to insert image in picturebox on the click of button throw system
Posted
Updated 12-Sep-18 14:55pm
Comments
bhagirathimfs 5-Jul-12 6:50am    
Can you please explain the question briefly..
narazalok 5-Jul-12 7:31am    
Hi, thanks for reply
Actually I create a form in c# and then take a picturebox and a button
Then I want to insert a image in picturebox on the click on the button
And the image that i want to take is stored in my system
bhagirathimfs 5-Jul-12 8:47am    
you want a image upload-er???
Pasan Eeriyagama 5-Jul-12 6:59am    
Your Question is not much clear.. bt check the solution below.. it may helpful.

On button click event you can load image by creating object of Image class like
C#
Image img=Image.FromFile("path of file");


And then load it by using image property of PictureBox like
C#
PictureBox.Image =img;


After that I guess you want to save that image to another location for that you can use Copy method of File class like
C#
File.Copy(sourceaddress,destinationadress);


Hope this will solve your problem.
 
Share this answer
 
Hi, Your Question is not clear.. But try this one. The Image should be in the folder where your EXE is running.

Image image = Image.FromFile("image123.png");
pictureBox1.Image = image;
 
Share this answer
 
v2
Comments
narazalok 5-Jul-12 7:26am    
Hi, thanks for reply
Actually I create a form in c# and then take a picturebox and a button
Then I want to insert a image in picturebox on the click on the button
And the image is stored in my system
nj15 5-Jul-12 23:39pm    
you mean that the image is saved in the system or in the database?
Pasan Eeriyagama 6-Jul-12 4:43am    
In case if you want to keep the image inside your app and use it, you may need to add it to Project Resources. Please see my example code below on how you should refer it..
If you want to keep the image inside your app. you may add it to resources of the project. and then refer it as below example.

cnt.BackgroundImage = MyProjectName.Properties.Resources.Button_background;
 
Share this answer
 
Image imgObj=Image.FromFile("path of file");
path of file like
"@c://foldername/img.jpg"
 
Share this answer
 
C#
private void button2_Click(object sender, EventArgs e)
       {
           string filename;

           openFileDialog1.ShowDialog();
           openFileDialog1.Filter = "JPEG files|*.jpg|PNG files|*.png|GIF Files|*.gif|TIFF Files|*.tif|BMP Files|*.bmp";

           filename = openFileDialog1.FileName;

           Image img = Image.FromFile(filename);
           pictureBox1.Image = img;

       }
 
Share this answer
 

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