【问题标题】:problem :globalization in C# using VS2005问题:使用 VS2005 在 C# 中进行全球化
【发布时间】:2008-12-29 13:46:26
【问题描述】:

我想全球化我的应用程序。 我创建了一个小表单,询问用户他们的语言。 我有很多问题:

问题一:

在程序.cs中

new SplashScreen(_tempAL);
new LangForm(_lang);
Application.Run(new Form1(_tempAL, _lang)); 

我希望应用程序在用户单击 LangForm 中的 OK 之前不要调用 Form1。 有关 LangForm 中的更多解释:

    public LangForm(char _langChar)
    {
        InitializeComponent();
        _ch = _langChar;
        this.TopMost = true;

        this.Show();

    }

    private void _btnOk_Click(object sender, EventArgs e)
    {
        string _langStr = _cbLang.SelectedText;
        switch (_langStr)
        {
            case "English":
                _ch = 'E';
                this.Hide();
                break;
            case "Arabic":
                _ch = 'A';
                this.Hide();
                break;
            case "Frensh":
                _ch ='F';
                this.Hide();
                break;
        }
        _pressedOk = true;
    }

    private void _btnCancel_Click(object sender, EventArgs e)
    {
        this.Close();
        Application.Exit();
    }

现在,当我调试时,应用程序调用 LangForm,然后调用 Form1,因此两种形式都显示出来。 我希望 Form1 等到用户在 LangForm 中点击 Ok。

问题 2:

我应该什么时候检查语言?不允许签入“initializeComponent()” 所以我应该在这个函数之后检查,然后根据语言设置控件位置。

问题 3:

在应用程序进程中,我会在每个“MessageBox.Show("");" 之前显示一些消息我应该检查语言,或者有另一种方法可以设置语言一次。

问题 4:

我已经搜索了 MessageBox 的接口,因为实际上我想更改它的布局。如何找到 MessageBox 的模板?

提前致谢。

【问题讨论】:

    标签: c#


    【解决方案1】:

    将语言选择表单显示为对话框。使您的 Program.cs 文件如下所示:

    [STAThread]
    static void Main() {
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      if (DialogResult.OK == new LangForm().ShowDialog()) {
        Application.Run(new Form1());
      }
    }
    

    将此行添加到您的 _btnOK 点击处理程序:

    this.DialogResult = DialogResult.OK;
    

    【讨论】:

      【解决方案2】:

      要阻止表单关闭,请在LangForm 上使用.ShowDialog()。然后,我将设置文化(Thread.CurrentThread.CurrentCultureThread.CurrentThread.CurrentUICulture此表单关闭和创建新表单之间。完成此操作后,来自 resx 的任何内容都应正确加载。

      要更改 MsgBox 的布局(超出标准),您必须自己编写(它不支持此功能)。

      类似:

      [STAThread]
      static void Main() {
          Application.EnableVisualStyles();
      
          // find the culture we want to use
          bool cont;
          string languageCode;
          using (LangForm lang = new LangForm()) {
              cont = lang.ShowDialog() == DialogResult.OK;
              languageCode = lang.LanguageCode; // "en-US", etc
          }
          if (!cont) return;
      
          // set the culture against the UI thread
          Thread.CurrentThread.CurrentCulture =
              Thread.CurrentThread.CurrentUICulture =
                  CultureInfo.GetCultureInfo(languageCode);
      
          // show the main UI
          using (MainForm main = new MainForm()) {
              Application.Run(main);
          }
      }
      

      请注意,使用官方文化代码将使CultureInfo 等内容更容易使用;如果您想使用自己的候选名单,请使用枚举,并在某处编写方法:

      public static string GetCultureCode(MyCulture culture) {
          switch(culture) {
              case MyCulture.French: return "fr-FR";
              case MyCulture.English: return "en-GB";
              //...
              default: throw new NotSupportedException("Unexpected culture: " + culture);
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-08-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多