LTR和RTL语言之间的控制开关对准 [英] Control alignment switching between LTR and RTL languages

查看:1489
本文介绍了LTR和RTL语言之间的控制开关对准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然这个问题是足够通用到网上,我很感兴趣,尤其是的WinForms。

Although this question is general enough to apply to the web, I'm interested in WinForms in particular.

LTR和RTL语言之间的应用程序UI开关无事。 。结果

The application UI switches between LTR and RTL languages without incident. The only obstacle is placement of labels that are associated with input controls such as text boxes.

左到右://i.stack.imgur.com/fPxsL.png相对=nofollow>

Left to Right:

从右至左:结果

在RTL图像上的标签位置也应发生相应的变化。

The label placement on the RTL image should also change accordingly.

有没有一种普遍性的,程序化的方法来实现这一目标?

Is there a generalized, programmatic way to achieve this?

推荐答案

选项1

如果两个 RightToLeftLayout 从右至左属性是真实的,镜像将被打开表单,并控制布局和文本流将是从右到左。所以设置 RightToLeftLayout 为true,并设置从右至左来是有向左布局完整的权利。

If both the RightToLeftLayout and RightToLeft properties are true, mirroring will be turned on for the form, and control placement and text flow will be right-to-left. So set RightToLeftLayout to true and set RightToLeft to yes to have a complete right to left layout.

这顺便也窗体标题栏将被镜像及控制箱将在左侧显示。

This way also the form title bar will be mirrored and control box will be shown at left.

选项2

如果你不喜欢有从右到左标题栏和左边的控制箱,你应该创建你的左容器自己的权利,并把控制它,然后设置 RightToLeftLayout 容器真实的,并设置从右至左:

If you don't like to have right to left title bar and the control box at left, you should create your right to left container yourself and put controls in it and then set RightToLeftLayout of the container to true and set RightToLeft of the container to yes to have a complete right to left layout in the container without changing the layout of title bar and control box:

using System;
using System.ComponentModel;
using System.Windows.Forms;
public class ExPanel : Panel
{
    const int WS_EX_LAYOUTRTL = 0x400000;
    const int WS_EX_NOINHERITLAYOUT = 0x100000;
    private bool rightToLeftLayout = false;

    [Localizable(true)]
    public bool RightToLeftLayout
    {
        get { return rightToLeftLayout; }
        set
        {
            if (rightToLeftLayout != value)
            {
                rightToLeftLayout = value;
                this.RecreateHandle();
            }
        }
    }
    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams CP;
            CP = base.CreateParams;
            if (this.RightToLeftLayout &&
                this.RightToLeft == System.Windows.Forms.RightToLeft.Yes)
                CP.ExStyle = CP.ExStyle | WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT;
            return CP;
        }
    }
}



屏幕截图

下面是选项1 。再看关闭按钮在标题栏的左边:

Here is a screenshot of Option 1. Look at Close button at left side of title bar:

下面是选项2 的屏幕截图。再看关闭按钮在标题栏的右侧:

Here is a screenshot of Option 2. Look at Close button at right side of title bar:

这篇关于LTR和RTL语言之间的控制开关对准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆