0

I'm using a global .resx file for all of the strings in my project to simplify providing all of the translations we will need. So for each of my forms instead of setting Localizable to true, I instead create a global Resourcemanager manager in my constructor like this:

GlobalObjects::rm1 = gcnew System::Resources::ResourceManager(L"Hycal_PC_Software.AppLocalization", Assembly::GetExecutingAssembly());
InitializeComponent();

And then I set the Text values of various form elements like this:

this->fileToolStripMenuItem->Text = GlobalObjects::rm1->GetString(L"File");

Works fine when running the app, but now when I go to design view for a form I get the horrible error page instead of my form because it doesn't like the rm1->. In hindsight it seems obvious it wouldn't but what is the correct way to deal with this? I really don't want to have to have individual .resx files for each form, particularly because they will also contain all sorts of things I don't want to localize.

Angew is no longer proud of SO
  • 167,307
  • 17
  • 350
  • 455
Skanky
  • 129
  • 8
  • Maybe you placed this code to the part generated by form designer. Just move it to some other place, like Form_Load event handler. – Alex F Feb 02 '15 at 18:43
  • This is a big mistake, every localization service knows how to deal with the standard way that Winforms localization is implemented. You pay *extra* and cause glitches and bugs with a custom scheme. Don't do it. – Hans Passant Feb 02 '15 at 20:02
  • I have indeed added it to the part generated by form designer. So would you say I should set my strings as normal (so the UI is setup for non run time development work) and then overwrite them in the form load as the preferred solution. Makes sense, just wondered if there was a way to avoid the duplication but makes sense if there isn't. Thanks Hans but as I'm only setting strings I want to avoid the complexity of multiple resx files and using a single one does appear to be a common approach from what I've seen. – Skanky Feb 02 '15 at 21:12

0 Answers0