Windows Forms: How to create multi language using Resource Manager and Culture Info in C#
By FoxLearn 7/31/2017 10:07:37 PM 13.06K
How to make a multi-language application in C#
Step 1: Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "CultureExample" and then click OK
Step 2: Design your form as below
Create a new dataset, then add a Language table to your dataset as below
Step 3: Add code to handle your form as below
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Globalization; using System.Linq; using System.Resources; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace CultureExample { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnSave_Click(object sender, EventArgs e) { //Save data to xml file appData.WriteXml(string.Format("{0}/data.xml", Application.StartupPath)); //Write language to resource file ResourceWriter ren = new ResourceWriter(Application.StartupPath + "/resource.en-US.resources"); ResourceWriter rde = new ResourceWriter(Application.StartupPath + "/resource.de-DE.resources"); foreach(AppData.LanguagesRow row in appData.Languages.Rows) { ren.AddResource(row.ID, row.English); rde.AddResource(row.ID, row.German); } ren.Generate(); ren.Close(); rde.Generate(); rde.Close(); MessageBox.Show("Successfully saved.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void Form1_Load(object sender, EventArgs e) { //Read data from xml file appData.ReadXml(string.Format("{0}/data.xml", Application.StartupPath)); //Load language CultureInfo ci = new CultureInfo("de-DE"); Thread.CurrentThread.CurrentCulture = ci; Thread.CurrentThread.CurrentUICulture = ci; ResourceManager rm = ResourceManager.CreateFileBasedResourceManager("resource", Application.StartupPath, null); if (rm.GetString("0001") != null) lblMessage.Text = rm.GetString("0001"); } } }
VIDEO TUTORIALS
- Windows Forms: Advanced Filter DataGridView in C#
- Windows Forms: Progress Bar in C#
- How to create a Lucky Draw games in C#
- Windows Forms: Youtube Search with Paging in C#
- Windows Forms: How to Create a Random Password Generator in C#
- Windows Forms: Tag Control in C#
- Windows Forms: Wait Form Dialog in C#
- Windows Forms: Text to speech in C#
Categories
Popular Posts
Visual Studio: Auto increment version
03/22/2024
What is ARM architecture?
03/11/2024