Home > Software design >  How do I delete image from windows form app?
How do I delete image from windows form app?

Time:11-21

I added an image to my windows form app, using a picture box. I have it saved in the resources folder . I can't seem to delete it because when I try to, it says that it couldn't find the file.

I have tried other solutions but can't seem to get them working, and don't understand how they are supposed to work.The error:

My resources folder:

I tried to use the dispose method, but I couldn't get it working.

CodePudding user response:

Click the image in Solution Explorer, press F4 and check that it is Copy to Output Directory: "Copied if Newer".

When you debug/run your application out of Visual Studio, the exe is running out of the bin/Debug folder. You want to make sure you delete the image from the bin/Debug not the project folder.

The error is straight forward, you're trying to delete a file that doesn't exist at that location.

Perhaps put a breakpoint on a line like this above the File.Delete operation:

if (File.Exists(filePath)) {

CodePudding user response:

I found that I needed to delete the resources from the Resources.resx file, then I was able to just delete the files from the resources folder and it wouldn't say it couldn't find it anymore because there was no reason to find it!

  • Related