When I try to insert a picture file in the BackgroundImage property of a Panel, I get this error:
An item with the same key has already been added.
What does this mean?
As I mentioned in a comment, the culprit is almost certainly the resources file for the form in question. Either you've already added the picture file to another control on the form, in which case you need to select it from the list instead of adding a new copy of it. Or you've somehow ended up with a corrupted resources file. In that case, the simplest fix is to delete it and let the IDE generate a new one:
Find the form in your Solution Explorer window, and click the expando triangle on its left side.
You should see two files: FormName.Designer.cs
and FormName.resx
. Resources files always have the .resx
extension, so that's the one you're looking for. Click on it to select it.
Press the Delete key on your keyboard, or right-click on the item and select "Delete", to remove it from your solution.
A dialog box will appear, asking you to confirm the deletion. Click "OK".
Once that's done, you will have to re-add all of the images used by controls on your form one-by-one. The IDE will automatically generate a new resource file to hold the images, hopefully one that is not corrupted this time around.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With