2017-05-20 103 views
1

資源文件沒有得到新添加的形式創建時的本地化屬性設置爲true,在2012年VS本地化的WinForms

當我一種新的形式添加到項目中,本地化屬性設置爲true,構建應用程序,.resx文件不會被創建。

+1

您應該設置'Localizable'和'Language'屬性。可能你還沒有設置'Language'屬性。 ResX文件位於解決方案資源管理器中的「表格」節點下。看看這篇文章[如何在winforms中製作多語言應用程序](http://stackoverflow.com/q/32989100/3110834)。 –

+0

我已經設置了語言屬性,然後構建了應用程序。還沒創建resx文件。不僅僅是一個,我曾經爲馬拉蒂,Telegu和法國隊效力過。但是沒有一個.resx文件被創建。 – Shweta

回答

1

請仔細按照this walkthrough。我在VS 2012中做的實驗工作正常。

Step1。

將標籤貼到Form1上

設置Form1.Localizable =真

設置Form1.Language =默認

設置標籤的文本= 「世界,你好!」

enter image description here

第二步。

設置Form1.Language =俄羅斯

設置標籤的文本= 「Приветмир!」

enter image description here

這些步驟的資源文件後,在解決方案資源管理器中變得可見

enter image description here

現在添加以下代碼到Form1的構造

using System; 
using System.Windows.Forms; 

namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      switch (MessageBox.Show(
       "Press 'Yes' for default language, 'No' for Russian.", 
       "Language Option", MessageBoxButtons.YesNo)) 
      { 
       case System.Windows.Forms.DialogResult.Yes: 
        System.Threading.Thread.CurrentThread.CurrentUICulture = 
         System.Globalization.CultureInfo.CreateSpecificCulture(""); 
        break; 
       case System.Windows.Forms.DialogResult.No: 
        System.Threading.Thread.CurrentThread.CurrentUICulture = 
         System.Globalization.CultureInfo.CreateSpecificCulture("ru"); 
        break; 
      } 
      InitializeComponent(); 
     } 
    } 
} 

運行應用程序並查看結果。

該代碼的主要目的是爲了表明在調用方法InitializeComponent之前必須設置CurrentUICulture。但是,在實際應用中,通常會在程序啓動時設置CurrentUICulture屬性。所以代碼必須移到程序啓動的地方。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Threading.Tasks; 
using System.Windows.Forms; 

namespace WindowsFormsApplication1 
{ 
    static class Program 
    { 
     /// <summary> 
     /// The main entry point for the application. 
     /// </summary> 
     [STAThread] 
     static void Main() 
     { 
      Application.EnableVisualStyles(); 
      Application.SetCompatibleTextRenderingDefault(false); 
      switch (MessageBox.Show(
        "Press 'Yes' for default language, 'No' for Russian.", 
        "Language Option", MessageBoxButtons.YesNo)) 
      { 
       case System.Windows.Forms.DialogResult.Yes: 
        System.Threading.Thread.CurrentThread.CurrentUICulture = 
         System.Globalization.CultureInfo.CreateSpecificCulture(""); 
        break; 
       case System.Windows.Forms.DialogResult.No: 
        System.Threading.Thread.CurrentThread.CurrentUICulture = 
         System.Globalization.CultureInfo.CreateSpecificCulture("ru"); 
        break; 
      } 
      Application.Run(new Form1()); 
     } 
    } 
} 

如果您爲應用程序定義UI語言設置,那麼您可以使用此處的設置值並設置UI語言。它會影響您在應用程序中定義的所有表單。

+0

Thanx Bahrom.That解決了我的問題。 – Shweta