問題描述
雖然這個問題很籠統,可以應用于網絡,但我對 WinForms 尤其感興趣.
Although this question is general enough to apply to the web, I'm interested in WinForms in particular.
應用程序 UI 在 LTR 和 RTL 語言之間切換而不會發生意外.唯一的障礙是放置與文本框等輸入控件相關的標簽.
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.
從左到右:
從右到左:
RTL 圖像上的標簽位置也應相應更改.
The label placement on the RTL image should also change accordingly.
是否有一種通用的、程序化的方式來實現這一點?
Is there a generalized, programmatic way to achieve this?
推薦答案
選項 1 - 鏡像表單(也可以鏡像標題欄)??
如果 RightToLeftLayout
和 RightToLeft
屬性都為 true,則會為表單打開鏡像,并且控件放置和文本流將是從右到左的.因此,將 RightToLeftLayout
設置為 true 并將 RightToLeft
設置為 yes 以獲得完整的從右到左布局.
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
container 為 true 并將容器的 RightToLeft
設置為 yes 以在容器中具有完整的從右到左的布局,而不改變標題欄和控制框的布局:
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 語言之間的對齊切換的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!