Introduction
This tip explains how to convert English language to Arabic language in Windows Forms C#.
Using the Code
Step 1
Create MDI forms in Windows Forms Application figure 1.
Figure 1
Then make some designs using two menustrips, see figure 2.
Figure 2
Then, make a new folder named language. Then add two resource files, open one resource file, add the corresponding Arabic word instead of English menu items. See figure 3.
Figure 3
Next, open resource2 file and add the corresponding English word instead of menus strip. See figure 4.
Figure 4
Create table on SQL server, then update code status to whether English or Arabic. Add this code.
The source code is as given below:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Resources;
using System.Globalization;
using System.Data;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
public partial class MDIForms : Form
{
private int childFormNumber = 0;
public MDIForms()
{
InitializeComponent();
}
ResourceManager res_man;
CultureInfo cul;
private void switch_language()
{
menuItem1.Text = res_man.GetString("menuItem1", cul);
menuItem2.Text = res_man.GetString("menuItem2", cul);
menuItem3.Text = res_man.GetString("menuItem3", cul);
menuItem4.Text = res_man.GetString("menuItem4", cul);
menuItem5.Text = res_man.GetString("menuItem5", cul);
menuItem6.Text = res_man.GetString("menuItem6", cul);
menuItem7.Text = res_man.GetString("menuItem7", cul);
menuItem8.Text = res_man.GetString("menuItem8", cul);
menuItem9.Text = res_man.GetString("menuItem9", cul);
menuItem10.Text = res_man.GetString("menuItem10", cul);
menuItem11.Text = res_man.GetString("menuItem11", cul);
menuItem12.Text = res_man.GetString("menuItem12", cul);
menuItem13.Text = res_man.GetString("menuItem13", cul);
menuItem14.Text = res_man.GetString("menuItem14", cul);
menuItem15.Text = res_man.GetString("menuItem15", cul);
menuItem16.Text = res_man.GetString("menuItem16", cul);
menuItem17.Text = res_man.GetString("menuItem17", cul);
menuItem18.Text = res_man.GetString("menuItem18", cul);
menuItem19.Text = res_man.GetString("menuItem19", cul);
menuItem20.Text = res_man.GetString("menuItem20", cul);
menuItem21.Text = res_man.GetString("menuItem21", cul);
menuItem22.Text = res_man.GetString("menuItem22", cul);
menuItem23.Text = res_man.GetString("menuItem23", cul);
menuItem24.Text = res_man.GetString("menuItem24", cul);
menuItem25.Text = res_man.GetString("menuItem25", cul);
menuItem27.Text = res_man.GetString("menuItem27", cul);
menuItem28.Text = res_man.GetString("menuItem28", cul);
menuItem29.Text = res_man.GetString("menuItem29", cul);
menuItem30.Text = res_man.GetString("menuItem30", cul);
menuItem31.Text = res_man.GetString("menuItem31", cul);
menuItem32.Text = res_man.GetString("menuItem32", cul);
}
private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (Form childForm in MdiChildren)
{
childForm.Close();
}
}
private void logOutToolStripMenuItem_Click(object sender, EventArgs e)
{
res_man = new ResourceManager("WindowsFormsApplication1.language.Resource",
typeof(MDIForms).Assembly);
cul = CultureInfo.CreateSpecificCulture("Ar");
switch_language();
menuStrip.Font = new Font("Segoe UI", 12, FontStyle.Regular);
menuStrip1.RightToLeft = RightToLeft.No; ;
menuStrip.Dock = DockStyle.Right;
}
private void eNGLISHToolStripMenuItem_Click(object sender, EventArgs e)
{
res_man = new ResourceManager("WindowsFormsApplication1.language.Resource",
typeof(MDIForms).Assembly);
cul = CultureInfo.CreateSpecificCulture("en");
switch_language();
menuStrip.Font = new Font("Segoe UI", 12, FontStyle.Regular);
menuStrip1.RightToLeft = RightToLeft.Yes; ;
menuStrip.Dock = DockStyle.Left;
}
}
}
The output will be as shown in figure 5.
Figure 5
Next, we can design child form for sample Arabic conversion by adding a new form, adding some labels and controls. See figure 6.
Figure 6
The source code for change language child form is as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Resources;
using System.Globalization;
using System.Data;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string activation_status = "English";
private void switch_language()
{
label2.Text = "رقم الهوية";
label3.Text = "فئة عامل";
label23.Text = " بمهن عامل";
label4.Text = "اسم";
label5.Text = "لقب العائلة";
label6.Text = "جنس";
label7.Text = "تاريخ ميلاد";
label8.Text = "تاريخ الانضمام";
button8.Text = "وفر";
btnClear.Text = "صافي";
btnClose.Text = "إغلاق";
panel1.Dock = DockStyle.Right;
panel3.Dock = DockStyle.Right;
panel2.Dock = DockStyle.Right;
}
ResourceManager res_man;
CultureInfo cul;
public void langugechange()
{
if (activation_status == "Arabic")
{
switch_language()
}
else if (activation_status == "English")
{
}
}
private void Form1_Load(object sender, EventArgs e)
{
langugechange();
}
}
}
The output will be as shown in figure 7. You can change language activation status in SQL Server now given directly.
Summary
In this tip, we discussed how to convert English language to Arabic language in Windows Forms C#. After that, we discussed how to use its various properties and methods to build real Middle East world applications.
You can also read my other tip at http://www.codeproject.com/Tips/862644/Arabic-Calendar-Date-to-English-Calendar-Date-Wind.