views:

46

answers:

4

I want to display a picture that is of jpeg type onto my interface. I want that picture to be displayed when my program is being executed. I'm doing this:

private void frmMain_Load(object sender, EventArgs e)
{
     LoadRecords();
     Image.FromFile("@ C:\Users\cAndyb0eMeh\Documents\Downloads\images.jpeg");        
} 

But this doesn't work. I get errors.

A: 

You'll need somewhere to put that picture, like a PictureBox control. You can one to your form from Visual Studio's ToolBox. When you add one, it is named PictureBox1 by default. So, in your form load event, you'd have:

PictureBox1.Image = Image.FromFile("@ C:\Users\cAndyb0eMeh\Documents\Downloads\images.jpeg");

The way you're doing it now, the image doesn't go anywhere.

codekaizen
i do the same thing as above into the picture box? i mean the code is correct?
Abid
I updated my answer to answer your question.
codekaizen
+3  A: 

Try this (your @ is in the wrong place):

private void frmMain_Load(object sender, EventArgs e) { 
 LoadRecords();      
 pictureBox1.Image = Image.FromFile(@"C:\Users\Andy Meh\Documents\Downloads\images.jpeg");
}
Naeem Sarfraz
+1 although the string seems to have got mangled in your answer. you also need to remove the initial space
AdamRalph
ok.. but.. is the code correct for inserting a picture? and yeah.. before doing doing that i need a picture box so that it stores a picture.. here.. the picture is not going any where
Abid
that is true. how about giving that a try and then if you have any specific problems, ask?
AdamRalph
@Abid - check my post for how to display the image.
codekaizen
@Abid, drop a picture box onto your form and just add just set the Image to the Image you've just loaded, as above
Naeem Sarfraz
A: 

you have to use "\\" for mentioning the path.

pictureBox1.Image = Image.FromFile"c:\\Users\cAndyb0eMeh\\Documents\\Downloads\\images.jpeg");

Pavan Navali
Not when you prepend it with @ before the quotation marks. This marks it as a verbatim string literal and escape characters are ignored.
xan
I think so. I have only used the version which I have mentioned above in which there is no '@'.
Pavan Navali