Errors after changing tool strip button image

92 Views Asked by At

Once i add this line to the code:

this.tsbAdd.Image = Bitmap.FromFile(@"..\..\Resources\add.bmp");

I'm unable to open editor of that form.

Screenshot of designer

I can compile app and images work as they should.

Expected results - new image is displayed without breaking designer.

Real results - new image breaks designer.

Once i build it into .exe it doesn't open. Without images it works flawlessly.

1

There are 1 best solutions below

6
On BEST ANSWER

Nope it won't. The picture will be built, but referencing it by this path won't be working.

The resource file WOULD be built into your exe, but not at "....\Resources\add.bmp". This path only exists in your IDE configuration position, when your program is at "bin\Debug", you understand me?

Imagine you put your exe into C:\, then where is "....\Resources"? You cannot refer to a image in this way.

You should add resources in the project panel (I believe you have done that), and the way you get this file is via ResourceManager, not using this path. Like this:

ResourceManager rm = Resources.ResourceManager;
this.tsbAdd.Image = (Image) rm.GetObject("add");

The resourcemanager will pull the resource bitmap out from your built exe. Just using that path won't work. As the designer is not ran in \bin\Debug, no wonder it is broken too because it cannot find your file using that path.