Will this work? if (buttonEnableScrew1.Text == "ENABLED")

S

Sonnich Jensen

Hi

I am updating an app, and found this:


if (buttonEnableScrew1.Text == "ENABLED")


now the app is in English and Hungarian, so the text can change

The language is updated like this:

ComponentResourceManager resources = new
ComponentResourceManager(typeof(ControlCell));

// iterate through all the controls and their sub-controls
and replace their names
foreach (Control c in this.Controls)
{
foreach (Control d in c.Controls)
{
foreach (Control e in d.Controls)
{
etc...
}
resources.ApplyResources(c, c.Name, new
CultureInfo(lang));
}


Now, when reading the "text" property, what will i then get?

Sonnich
 
S

Sonnich Jensen

Yes, that code seems a bit wrong.  The program should not depend on
localizable state to control program flow.













Impossible to say, since you didn't provide a complete code example. It's
possible that the call to ApplyResources() would set the Text property of
each control passed to it.  Maybe it's even _likely_ it would do that.

But we don't know what values are in your resources, nor which controls
would actually be enumerated by that loop (the non-recursive,
explicitly-nested enumeration certainly leaves open the possibility that
some of the controls contained at some level in the top-most control may be
missed).

In any case, it's a bit odd that you would ask that question here, since
the easiest way to answer your question is to run the code and see what
happens.

Pete

Well, just got it, so I have already replaced some of this style of
code, and that was a good idea.
There are other very interesting things in that code :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top