Exemplo n.º 1
0
        // Note: Needs WindowManager instance for automatic change.
        private void changeCulture(CultureInfo culture)
        {
            if (culture == null)
            {
                return;
            }
            ChangeCultureEventArgs e = new ChangeCultureEventArgs(culture);

            CultureChanging?.Invoke(this, e);
            if (e.Success)
            {
                Settings.Default.Culture = culture.Name;
                Settings.Default.Save();
                this.Close();
                return;
            }
            if (!e.SuppressDefault)
            {
                if (MessageBox.Show(Resources.InfoWindow_RestartNewLang, "", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)
                    == DialogResult.OK)
                {
                    Settings.Default.Culture = culture.Name;
                    Settings.Default.Save();

                    /* Explicitly close the owner form if available to ensure closing events are called:
                     *  https://stackoverflow.com/a/13527298/9145461 */
                    this.Owner?.Close();
                    System.Windows.Forms.Application.Exit();
                    if (Environment.GetCommandLineArgs().Length > 1)
                    {
                        string[] args = new string[Environment.GetCommandLineArgs().Length - 1];
                        Array.Copy(Environment.GetCommandLineArgs(), 1, args, 0, args.Length);
                        Process.Start(System.Reflection.Assembly.GetEntryAssembly().Location, String.Join(" ", args));
                    }
                    else
                    {
                        Process.Start(System.Reflection.Assembly.GetEntryAssembly().Location);
                    }
                }
            }
        }
Exemplo n.º 2
0
        // Note: Needs WindowManager instance for automatic change.
        private void changeCulture(CultureInfo culture)
        {
            if (culture == null)
            {
                return;
            }
            ChangeCultureEventArgs e = new ChangeCultureEventArgs(culture);

            CultureChanging?.Invoke(this, e);
            if (e.Success)
            {
                Properties.Settings.Default.Culture = culture.Name;
                Properties.Settings.Default.Save();
                this.Close();
                return;
            }
            if (!e.SuppressDefault)
            {
                if (MessageBox.Show(Properties.Resources.InfoWindow_RestartNewLang, "", MessageBoxButton.OKCancel, MessageBoxImage.Warning)
                    == MessageBoxResult.OK)
                {
                    Properties.Settings.Default.Culture = culture.Name;
                    Properties.Settings.Default.Save();
                    System.Windows.Application.Current.Shutdown();
                    if (Environment.GetCommandLineArgs().Length > 1)
                    {
                        string[] args = new string[Environment.GetCommandLineArgs().Length - 1];
                        Array.Copy(Environment.GetCommandLineArgs(), 1, args, 0, args.Length);
                        Process.Start(System.Reflection.Assembly.GetEntryAssembly().Location, String.Join(" ", args));
                    }
                    else
                    {
                        Process.Start(System.Reflection.Assembly.GetEntryAssembly().Location);
                    }
                }
            }
        }