2008-12-29 1 views
1

我想全球化我的應用程序。 我創建了一個詢問用戶語言的小形式。 我有一些問題:問題:使用VS2005的C#中的全球化

問題1:

在Program.cs的

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

我希望應用程序不調用Form1中,直到用戶點擊OK的LangForm。 對於LangForm更多explaintion:

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的模板?

非常感謝。

回答

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; 
1

要阻止表單關閉,請在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); 
    } 
}