Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to show image on form load using code on picturebox.
Posted

See this code as a reference:
C#
private void Form1_Load(object sender, EventArgs e)
{
  pictureBox1.Image = new Bitmap("C:\\Temp\\Test.jpg");
}
 
Share this answer
 
Comments
dmunisubbu 5-Sep-12 0:18am    
its nice
AmitGajjar 5-Sep-12 1:07am    
I prefer relative path.
try this code

create folder like this
D:\\Yourprojectname\bin\Debug\images and put your image here.

then write below piece of code

C#
private void Form2_Load(object sender, EventArgs e)
   {
    pictureBox1.Image = Image.FromFile(Application.StartupPath + "\\images\\yourimage.jpg");
   }
 
Share this answer
 
v2
Comments
dmunisubbu 5-Sep-12 0:18am    
fine dude
Oshtri Deka 5-Sep-12 1:52am    
Wouldn't a Resources be a more convenient place to store an image?
My answer is same as those by JF2015 and D-Kishore, but I would put my picture in Resources.
Then I could write something like this:
C#
private void MyForm_Load(object sender, EventArgs e)
{
   myPictureBox.Image = Properties.Resources.MyPicture;
}
 
Share this answer
 
v2

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