2

I have project and it supports 4 languages but now customer wants one more language. It is Arabic. I have no idea how to display Arabic in Labels and TextBoxes.

I know Arabic is written from right to left and its starting point is the right side of the label ord textview.

here is my sample code. this code show english,german and arabic....

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {

        if (comboBox1.SelectedItem.ToString().Equals("en-GB"))
        {
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-GB");
            label1.Text= FormLabels.test1;
            label2.Text = FormLabels.test2;
        }
        else if (comboBox1.SelectedItem.ToString().Equals("de-DE"))
        {
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE");
            label1.Text = FormLabels.test1;
            label2.Text = FormLabels.test2;
        }
        else if (comboBox1.SelectedItem.ToString().Equals("ar"))
        {
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("ar");
            label1.Text = FormLabels.test1;
            label2.Text = FormLabels.test2;
        }
    }

How am I supposed to display Arabic characters and display the test from right to left?

4

2 回答 2

2
 //...
 else if (comboBox1.SelectedItem.ToString().Equals("ar"))
    {
        Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("ar");
        label1.RightToLeft = label2.RightToLeft = RightToLeft.Yes;
        label1.Text = FormLabels.test1;
        label2.Text = FormLabels.test2;
    }

更新

如果您有很多标签,这里有一些解决方案:

  1. 您可以定义一个名为 RightToLeftLabel 的类,并使用它来声明所有标签:

    public class RightToLeftLabel : Label {
        public RightToLeftLabel(){
           RightToLeft = RightToLeft.Yes;
        }
    }
    //Then declare your labels:
    RightToLeftLabel label1 = new RightToLeftLabel();
    RightToLeftLabel label2 = new RightToLeftLabel();
    RightToLeftLabel label3 = new RightToLeftLabel();
    //you can also drag-n-drop this custom Label from the ToolBox (remember to place the class in your project namespace and build first, after that you will see there is a RightToLeftLabel control at the very top in the ToolBox)
    
  2. 您可以遍历标签集合并更改RightToLeftYes每个标签:

    foreach(Label lbl in yourLabels)
         lbl.RightToLeft = RightToLeft.Yes;
    //I think this is right for you because the project language may change...
    
于 2013-07-31T11:14:31.317 回答
2

我想补充一下 kingKing 的答案,一如既往地出色,您应该考虑制作所有表格RightToLeft,因为当您阅读表格时,您无法阅读表格RightToLeft并以相反的方式进行控制。这是我的意思的一个例子:如果它是翻译成英文的阿拉伯形式:

在此处输入图像描述

于 2013-07-31T11:18:20.950 回答