How to make RightToLeftLayout work for controls inside GroupBoxes and Panels?(如何使 RightToLeftLayout 适用于 GroupBoxes 和 Panels 中的控件?)
问题描述
According to MSDN
form.RightToLeftLayout = True;
form.RightToLeft = ifWeWantRTL() ? RightToLeft.True : RightToLeft.False;
is enough to mirrow the form content for RTL languages.
But controls placement gets mirrowed only for controls immediately on the form,
those inside a GroupBox or a Panel are not mirrowed, unless I put them on a TableLayoutPanel or a FlowLayoutPanel fisrt.
This is a lot of manual work to place a TableLayoutPanel inside each GroupBox, and especially to rearrange the controls (one control per table cell, padding, margin, etc)
Is there an easier way to make mirrowing work for all controls?
Or at least, how can I bypass the rearranging step, for it is quite a task with our number of forms?
Edit: RightToLeft property for each control on the form by default is inherited,
so Panels and GroupBoxes always have the needed RightToLeft setting.
Nevertheless, I tryed to reassign it for them both programmatically and from designer, it did not help.
It does seen that you have quite a nasty problem on your hands. Have played with it for a while and come up with the following:
Making use of a little recursion you can run though all the controls and do the manaul RTL conversion for those controls trapped in Pannels and GroupBoxes.
This is a quick little mock of code that I slapped together. I would suggest you put this in your BaseForm (heres hoping you have one of these) and call on base form load.
private void SetRTL (bool setRTL)
{
ApplyRTL(setRTL, this);
}
private void ApplyRTL(bool yes, Control startControl)
{
if ((startControl is Panel ) || (startControl is GroupBox))
{
foreach (Control control in startControl.Controls)
{
control.Location = CalculateRTL(control.Location, startControl.Size, control.Size);
}
}
foreach (Control control in startControl.Controls)
ApplyRTL(yes, control);
}
private Point CalculateRTL (Point currentPoint, Size parentSize, Size currentSize)
{
return new Point(parentSize.Width - currentSize.Width - currentPoint.X, currentPoint.Y);
}
这篇关于如何使 RightToLeftLayout 适用于 GroupBoxes 和 Panels 中的控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使 RightToLeftLayout 适用于 GroupBoxes 和 Panels 中的控件?
基础教程推荐
- C# 9 新特性——record的相关总结 2023-04-03
- 如果条件可以为空 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 将数据集转换为列表 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
