简体   繁体   中英

what is the correct way to change the directions of Winforms controls

what is the correct way to change the directions/position of Winforms controls, so it supports for example languages that start from Right-To-Left , programmatically so it's one form , one design, but when I switch the languages , it's switches it's position and directions.

EDIT: after checking @vcsjones answer ;

it worked with the layout ,but the controls position didn't change. here an image 在此处输入图片说明

I have tried nested loops to change the direction , but it didn't work :

    if (Constantes["RightToLeft"] != null && Constantes["RightToLeft"].ToLower().Equals("true"))
    {
        RightToLeft = RightToLeft.Yes;
        RightToLeftLayout = true;


        foreach (Control c in base.Controls)
        {
            foreach (Control item in c.Controls)
            {
                foreach (Control i in item.Controls)
                {
                    i.RightToLeft = RightToLeft.Yes;
                }
                item.RightToLeft = RightToLeft.Yes;
            }
            c.RightToLeft = RightToLeft.Yes;
        }

    }

WinForms can already handle this reasonably well using the right-to-left unicode character. For example:

button1.Text = "\u202EHello World";

This will display the button's text way like this:

RTL你好世界

Most likely, your text of your application will be done using localization files. If you use the RTL unicode character in the strings of your localization file, then you do not need to do any special coding - that unicode character is handled by WinForms already.

Setting these two properties will also switch around the control layout of the window:

RightToLeftLayout = true;
RightToLeft = RightToLeft.Yes;

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM