Why is everything in Form.resx automatically cleaned after saving Form.designer.cs in Visual Studio 2013?

StackOverflow https://stackoverflow.com/questions/23359195

  •  11-07-2023
  •  | 
  •  

It is my first time to use resx file to store strings in Visual Studio. It's so weird that when I modified something on designer.cs, and saved it, all strings in resx were gone. Does anyone meet this issue before? How to solve it? Thanks!

有帮助吗?

解决方案

You should not edit Form.resx files manually. Together with Form.Designer.cs files they should only be edited with the use of winform designer.

Form.resx and Form.locale.resx files contains all resources associated with that form controls: icons, cursors, images, localization strings, etc.

If you need to put custom resources, then simply create separate resx-files (see here of how to work with them).

It is still a question, if you really need to use resource files. Having static class to store strings is much more comfortable way, you will have all power of intellisence (find all references, no spelling errors, etc), while accessing resources required specifying identificator, where you can very easily make a mistake or two. If you think about localization, then it's different story (but still, you can use reflection and text-files to have it way more comfortable then microsoft satellite way).

其他提示

Form.resx is only used by WinForms designer, so leave it alone in all cases.

The contents stored in such designer managed resource files can be,

  • Form icons
  • Control tooltips if their contents are longer than a predefined length
  • ImageList contents
  • and many other (which is undocumented)

Like @Kilazur pointed out, you should store your own resources in newly created resource files that are not controlled by the designer.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top