When should you set RightToLeftLayout and RightToLeft?

I got a question from a previous post, about when should we set RightToLeftLayout, and RightToLeft in the code. His scenario is as follows:

He has a multi lingual Windows Forms application. In the case of Arabic, he sets RightToLeft at runtime, depending on a value in his resources. If his UI is English then there is no need to set RightToLeft.

His question is:

When should I set RightToLeftLayout and RightToLeft? I tried to set them on Form.Load but the Form was flickering and it didn’t look good.

The solution is:

First, for RightToLeftLayout: if you decide to set RightToLeftLayout to true, you can set it for any language since it doesn't have effect unless RightToLeft.Yes is set. So please set RightToLeftLayout at design time, for needed controls.

 

Second, for RightToLeft: you should set it in the Form constructor and not the Form.Load. Follow these easy steps:

 

1) [In case of VB] Overload your form, “New” sub:

2) After initializing the component set the RightToLeft property.

Your code should look like this:

 

VB

 

    Public Sub New()

        ' This call is required by the designer.

        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        'Not needed Me.RightToLeftLayout = True

        Me.RightToLeft = Windows.Forms.RightToLeft.Yes

    End Sub

 

C#

     public Form1()

        {

            // This call is required by the designer.

            InitializeComponent();

            // Add any initialization after the InitializeComponent() call.

    // Not needed Me.RightToLeftLayout = True

            this.RightToLeft = RightToLeft.Yes;

        }

 

 

This fixed the flickering and I hope you find this info useful too.