문제

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?

도움이 되었습니까?

해결책

 //...
 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;
    }

UPDATE

if you have many many labels, there are some solutions here:

  1. You can define a class such as called RighToLeftLabel and use it to declare all your labels:

    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. You can loop though the collection of your Labels and change RightToLeft to Yes for each one:

    foreach(Label lbl in yourLabels)
         lbl.RightToLeft = RightToLeft.Yes;
    //I think this is right for you because the project language may change...
    

다른 팁

i want to add on kingKing answer, which is excellent as always, that you should consider making all the form RightToLeft, because when you read the form you can't read the form RightToLeft and have the control in a reverse way. here is an example of what i mean: if it was an arabic form translated to english:

enter image description here

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top