Jame
Jame

Reputation: 22180

C#: Picture Box control not working properly

I am developing a new desktop application in C# using Windows Forms. In one of my form i put the "Picture Box" control which dynamically loads a new pic, each time when user performs a specific operation. The code for changing picture is as follow:

this.pictureBox1.Image = Image.FromFile(PicURI);

The only problem which i face is that some time it displays a red cross rather than displaying proper image. I debug the application and find that PicURI contains the proper path of image as expected so i don't understand where does the problem lies?

Edit: Change Code from

this.pictureBox1.Picture = Image.FromFile(PicURI);

to

this.pictureBox1.Image = Image.FromFile(PicURI);

Upvotes: 1

Views: 2536

Answers (3)

Vikram Singh Saini
Vikram Singh Saini

Reputation: 1879

He is using some user control with picture box in it. The Picture is public property in user control which return the image of pictureBox.

I think it display red cross because you had set the red cross image in user control's picture box. Some of the picture format are unreadable directly from Image.FromFile() and for that case it's showing same.

Upvotes: 0

NaveenBhat
NaveenBhat

Reputation: 3318

Are you really using PictureBox? it doesn't have Picture property. If you really mean PictureBox, you could use Image property as suggested by deepi

EDIT:

Red Cross Indicates that an Exception has been thrown inside. Since PictureBox has handled the exception, you are not aware of that. However, you can set the VS to break when exception occurs(even though it is handled), by checking the CheckBox Thrown for a particular exception on Debug -> Exceptions

Refer: http://msdn.microsoft.com/en-us/library/d14azbfh.aspx

Upvotes: 2

deepi
deepi

Reputation: 1081

Try like this

this.pictureBox1.Image = Image.FromFile(PicURI);

Upvotes: 4

Related Questions