Reputation: 1175
I have trying to learn about resources. In VS when I create the project:
-there is Form1 with Form1.resx
-there is Resources.resx under Properties
I do not know which one to use. Obviously I cannot use Form1.resx. When I try to add something there, I get a warning the it might mess up the project. In addition, I cannot access it. If I use the Resources.resx under Properties, I can easily access the files there just using Properties.Resources.(filename). What is also the difference between these two? What are Form1.resx good for? Thank you
Upvotes: 3
Views: 3404
Reputation: 3453
Be extremely cautious when you toy with resx files in Visual Studio!!!!
Chances are you will soon crash your project when you try to change / add / edit / delete form's level resources.
You are better off using project's level resource file.
There are several types of resources, like Strings, Images, Audio, Icons, Files etc.
The project level resources are useful to share resources - mainly graphics - among all your forms:
You import a graphic once from Project Menu / myProject's Properties / Resources / Add existing file menu item.
Be wary that once you've added a resource, and USED that resource within your project, you should NOT remove it from the resource file whithout being CERTAIN you do not use it any more, otherwise the resource will be deleted, but NOT references against it, and you'll get compile time errror, or even worse, runtime errors.
Likewise, imageList control embeds graphics at the form's level. But those aren't shareable between forms, so if you think you're going tu re-use a graphic, you're better off adding it as a global resource at application - project's level.
Besides, imagelist are very difficult to maintain - evolve.
For copying an existing form to a new one, within the same project or another, DO NOT copy/paste the formxxx.vb file. Idem, do not copy / paste a resx file from one project to another.
Here is the rather cumbersome process you should use:
1 - To copy a form to the same project:
Provided there is NO custom form's level resources (added by you): Create a new empty form and make it the same size - and other properties as needed - as the original form. Yes, manually.
From the original form's design type Ctrl+A to select all its controls, and copy them to the new form.
They will keep theyr name and properties.
Do the same for the code: copy / paste. Pay attention to delete the 1st line after the Imports: Public Class myOriginalForm
2 - To copy form(s) to another project, you should first make sure all project's level resources are identical. And NOT by copying indiividual resources from the resource folder!
Instead, carefully Import the resources in the new project, using the Add Existing Resource menuitem. You can import several items at a time.
This way, your resources will be properly referenced.
Upvotes: 0
Reputation: 384
Form1.resx is good for embedding graphic objects directly in your Form1 code files. That way it's easy to cut and paste your that form into your other projects. Also, if you create another copy of Form1 called Form2, you can make changes to either one without worrying about those changes affecting the other form. Resources.resx works in just the opposite manner. If you make changes to a resouce in Resources.resx, all classes that use that resource will be updated. For example, if you have a filepath resource and you change the path, all classes that reference that resource will get the updated path.
Upvotes: 0
Reputation: 3948
Form1.resx is meant for the form and defines what it has as controls. You should also not try to hand-edit this one as it get regenerated when you make changes to UI using the VS designer
Resources.resx is meant for global(common) resources for the entire project. Generally meant for sharing stuff!
Upvotes: 1