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