2

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.

Community
  • 1
  • 1
Nallware
  • 159
  • 1
  • 4
  • 18
  • 1
    You should try calling `pictureBox1.Invalidate();`. Just guessing, because I really have no idea why what you have already wouldn't work. – Jashaszun Jul 30 '14 at 22:17
  • 1
    Several of your methods should work. I wonder why you didn't also try `pictureBox1.ImageLocation = yourPath;` But if none work the problem is elsewhere. Please show us the calls in their context and also make sure they are actually reached by putting a breakpoint on them! You may want to give your Picturebox a Border to make sure you can even __see__ it i.e. it is not hidden, displaced or size zero – TaW Jul 31 '14 at 05:54
  • @Jashaszun, please make your .Invalidate an answer. This is what worked for me and I'd like to accept it. – Nallware Jul 31 '14 at 21:22
  • 1
    @Nallware Happy to oblige! :) – Jashaszun Jul 31 '14 at 22:35

1 Answers1

1

You should try calling pictureBox1.Invalidate(). Usually that works for me when I need to make sure something gets repainted.

Jashaszun
  • 9,207
  • 3
  • 29
  • 57