如何使内部GroupBoxes和面板控制RightToLeftLayout工作? [英] How to make RightToLeftLayout work for controls inside GroupBoxes and Panels?

查看:298
本文介绍了如何使内部GroupBoxes和面板控制RightToLeftLayout工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据MSDN

form.RightToLeftLayout = True;
form.RightToLeft = ifWeWantRTL() ? RightToLeft.True : RightToLeft.False;

就足以mirrow为RTL语言形式的内容。

is enough to mirrow the form content for RTL languages.

但控制布局,仅得到了控制,立即在表格上mirrowed,
里面的人一个组框或面板不mirrowed ,除非我把它们放在一个TableLayoutPanel或FlowLayoutPanel的最前一页。

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.

这是一个很多事情把一个TableLayoutPanel每个组框里面, 特别是要重新排列控件(每个表格单元格,填充,保证金等一个控制)

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)

是否有更简单的方法,使mirrowing工作,对所有的控制?

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?


修改:RightToLeft属性的默认窗体上的每个控件是继承的,
所以面板和GroupBoxes总是有需要从右至左的设置。
不过,我trye​​d重新分配它他们两个编程和设计,它并没有帮助。

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:

利用一点点递归可以运行,虽然所有的控制和做manaul RTL转换为那些被困在Pannels和GroupBoxes控制。

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.

这是一个的快速的的code,我耳光一起模拟不大。我建议你​​把它放进你的基本形式(继承人希望你有其中之一),并呼吁基本形式的负载。

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);
}

这篇关于如何使内部GroupBoxes和面板控制RightToLeftLayout工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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