Click here to Skip to main content
15,868,080 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I create C# windows form project. my app have 2 language and user can switch between them. the program work correctly in debug mode, language change and the related form is show. But when I create setup file even after the language change, the language of form is not changing. why this happened?
please help.

What I have tried:

this is my language change button code:
if (MessageBox.Show(message.messageSettingChangeLanguage(), "",
                    MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2,
                    message.messageBoxAlign()) == DialogResult.Yes)
           {
               Properties.Settings.Default.languages = language;
               Properties.Settings.Default.Save();
               Application.Restart();
           }

and this is my program file code:

static void Main()
       {
           if (Properties.Settings.Default.languages == "Farsi")
           {
               Thread.CurrentThread.CurrentUICulture = new CultureInfo("fa-IR");
           }
           else if (Properties.Settings.Default.languages == "English")
           {
               Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
           }
           Application.EnableVisualStyles();
           Application.SetCompatibleTextRenderingDefault(true);
           Application.Run(new SplashScreenForm());
       }
Posted
Updated 28-May-23 20:42pm
v3
Comments
Graeme_Grant 29-May-23 1:40am    
Check the language file properties. Make sure they are both identical.
Member 15627495 29-May-23 1:43am    
Try with another constant DialogResult.yes,

use : 1 // As a boolean for 'yes'

a messagebox is not a 'commondialog' with const 'dialogresult' as feedback
OriginalGriff 29-May-23 2:38am    
Erm ... yes it is: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.messagebox.show?view=windowsdesktop-7.0
It returns a DialogResult enum value.

1 solution

That code:
if (MessageBox.Show(message.messageSettingChangeLanguage(), "",
                    MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2,
                    message.messageBoxAlign()) == DialogResult.Yes)
           {
               Properties.Settings.Default.languages = language;
               Properties.Settings.Default.Save();
               Application.Restart();
           }
Doesn't change the value of language, it just saves the current value. You should be toggling language between "Farsi" and "English" before you store it - or better still using an enum instead of a string so that you can only store known languages. A string allows for spelling mistakes when you use it.

I have no idea why this appears to work in dev - I suspect you are looking at old code or an old EXE file.
 
Share this answer
 
Comments
Member 11400059 29-May-23 8:27am    
no the language is input parameter that set when above code call. I check with debug point and find the language parameter is change and save correctly. also in debug mode the language and form is change, but in release mode and after create setup file in not worked.
OriginalGriff 29-May-23 8:55am    
How do you know it doesn't work? What does it do? How did you test it? What did you look at?

And how do you expect us to know when you change it given that we can't see your code!

And as a side thing, if you start faffing with Culture, you had better be damn careful - if you change mine from en-GB to en-US then all the dates I enter will get interpreted as MM-dd-yyyy when I enter them as dd-MM-yyyy and as a user I will be very cross with you ... and so would any DB admin!

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

  Print Answers RSS


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