Click here to Skip to main content
15,062,966 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello experts,

I've been badly hit by VS's poor handling of resources.
And this is not the first time...

I had some images on the project's Resources.resx file, which were used as icons for menus, toolbars, etc.
I've removed one of the images in order to replace it with another.
Then I switched back to my designer, in order to set the new image.

And that's when all hell broke loose!
My toolbar's items were gone! Menu's were gone!
Even status bar items! GONE!
They are declared in the designer generated code, but it appears that lines like SomeControl.AddRange(...) were erased!

As I said, that's not the first time it happend.
Previous solutions I used involved manually re-adding designer generated lines, and other ugly stuff like that.

How do I overcome the problem in the future, and how can I restore my controls?
Posted
Comments
Richard MacCutchan 16-Aug-10 17:04pm
   
With reference to your comment below, I'm not sure exactly what you are doing but the only time I have had a similar problem is when I have tried manual editing rather than using the form designer. I feel sure that if Visual Studio were as bad as you describe then Microsoft would be getting roasted by now.

I'm not familiar with the specific problem you are having, but if you are trying to keep designer generated code, I have a suggestion. Assuming you are working with C#, you can create partial classes (i.e., a class that is defined in multiple files). You can take the designer generated code you want and put it into your own file that the designer will hopefully not touch.
   
Comments
Shy Agam 16-Aug-10 15:33pm
   
It's a thought, but I still see it as too much manual handling and maintainance of code.
The short answer is never manually edit this file.

Take note of the following warning in your designer code file:
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>

This file is recreated any time you change anything in the layout of your form so unless you have modified it through the designer any manual changes you make will probably be lost.
   
Comments
Shy Agam 16-Aug-10 15:36pm
   
Well... That's not completely accurate...
As I mentioned earlier, that's how I get my controls re-added to their containing objects. :)
Another simple way to add images is, simply add them to your project as you will add any other file and set their build action to Embedded Resource.

And in order to use it you can simply get a bitmap object
Bitmap bitmap = new Bitmap (GetType (), "SomeImage.bmp");


Hope this would help you to avoid handling Resource files upto some extent.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900