Sonam Mohite
Sonam Mohite

Reputation: 903

RightToLeftLayout in Panel

I have a windows project (C#) which we are going to use for Arabia. As we know the country following Right to Left mechanism. How can i move my all controls position in panel in RTL(Right to left) format. I have set properties 'RightToLeft' and 'RightToLeftLayout' to true but it moves controls inside the form only not panel. See the example

enter image description here

I had applied said properties when controls moved which are simply on the form, but controls inside panel, remain as is.

Upvotes: 4

Views: 1971

Answers (3)

Mehdi Khademloo
Mehdi Khademloo

Reputation: 2812

you can use this control :)

class MyPanel:Panel
{
    private bool myRightToLeftLayout=false;
    public bool MyRightToLeftLayout
    {
        get { return myRightToLeftLayout; }
        set 
        {
            if (value != myRightToLeftLayout)
            {
                foreach (Control item in base.Controls)
                {
                    try
                    {
                        item.RightToLeft = value==true?RightToLeft.No:RightToLeft.Yes;
                        item.Location = new System.Drawing.Point(base.Size.Width - item.Size.Width - item.Location.X, item.Location.Y);
                    }
                    catch { }
                }
                myRightToLeftLayout = value;
            }
        }
    }
}

and the result like this

MyRightToLeftLayout = false

enter image description here

MyRightToLeftLayout = true

enter image description here

Upvotes: 8

Shekhar Pankaj
Shekhar Pankaj

Reputation: 9145

Facts about RightToLeftLayout:

  • It has effect if RightToLeft is set to Yes, only.
  • RightToLeftLayout is a Boolean property and the values are true or false RightToLeftLayout property is not inherited by its child controls.
  • Unlike the RightToLeft property you need to individually set the RightToLeftLayout to each individual control that supports this property.
  • RightToLeftLayout would change the origin of its control and mirror the coordinates. So the origin is at the top-right instead of the top-left of the control. The coordinates would then increase to the left, instead of the right.

so according to second point you need to set it to all individual child elements

Upvotes: 0

Khan
Khan

Reputation: 342

You can do two of the things :

Firstly, in Web.config file of the web application, set the culture attribute of the <globalisation> element to 'ar-SA'

Secondly, Set the HTML dir attribute for the element of each page to"rtl"

Upvotes: -2

Related Questions