Reputation: 159
I have a simple application in winforms where I need to change the image depending on an if statement. The statement is triggering because other things are also happening. I've looked at the following examples:
Dynamically set Image of a Picturebox in winforms applications?
Change PictureBox's image to image from my resources?
Setting a picture from my Resources programmatically to a PictureBox
and none of these have led me to a solution to why I'm unable to change the image.
Here's what I have tried:
pictureBox1.Image = global::KatReminder.Properties.Resources.angry_orange_cat;
pictureBox1.Refresh();
pictureBox1.Load();
pictureBox1.Image = Image.FromFile(@"\Resources\angry-orange-cat.jpg");
pictureBox1.BackgroundImage = KatReminder.Properties.Resources.angry_orange_cat;
pictureBox1.Refresh();
pictureBox1.Load(@"\Resources\angry-orange-cat.jpg");
In the two examples with files, the full path I'm using has been truncated for this example.
Upvotes: 2
Views: 10924
Reputation: 9270
You should try calling pictureBox1.Invalidate()
. Usually that works for me when I need to make sure something gets repainted.
Upvotes: 1