放置在TableLayout停靠控件不会自动尺寸比他们的创作尺寸更小 [英] Docked controls placed within TableLayout do not automatically size smaller than their creation size

查看:149
本文介绍了放置在TableLayout停靠控件不会自动尺寸比他们的创作尺寸更小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这问题比表现出解释,所以我给自己定了一个混帐回购协议与Visual Studio 2010的项目中使用看到行动的问题。

This issue is better demonstrated than explained, so I've set up a git repo with Visual Studio 2010 project that be used to see the issue in action.

我有,我已经添加了一个组合框控件的一个项目( comboField )到TableLayout控制(tableLayoutPanel1 <$ C C $> )。我的组合框的码头属性设置为填写,使其充满了TableLayout控制,它的细胞已被放置在,我也已经设置TableLayout控制的码头属性填写,使其充满了形成,它已被放置在。组合框的宽度是目前193像素。

I have a project where I've added a ComboBox control (comboField) to a TableLayout control (tableLayoutPanel1). I've set the Dock property of the ComboBox to Fill so that it fills the cell of the TableLayout control that it has been placed in. I've also set the Dock property of the TableLayout control to Fill so that it fills the Form that it has been placed on. The width of the ComboBox is currently 193 pixels.

当我运行的形式,并增加其宽度的组合框的大小增加,符合市场预期。当我减少窗体的大小,组合框的大小的减小,直到的达到它的原始大小(193像素)。在这一点,组合框的宽度不会降低任何进一步的,从而在控制的右手侧被裁剪。这违背了我所期望的:该组合框的宽度将减少到零,因为没有的minimumSize 已指定。无论是有一个的minimumSize 指定任何窗体上的其他控件,如TableLayout控制。

When I run the form and increase its width, the size of the ComboBox increases, as expected. When I reduce the size of the form, the ComboBox reduces in size until it reaches it's original size (193 pixels). At which point, the width of the ComboBox will not decrease any further, resulting in the right-hand side of the control being clipped. This is contrary to what I would expect: the width of the ComboBox will decrease to zero, given that no MinimumSize has been specified. Neither has a MinimumSize been specified for any of the other controls on the form, such as the TableLayout control.

在的情况下它是相关的,则TableLayout的第一列的宽度已被设定为100个像素的绝对大小,而第二列的宽度该TableLayout已设置为自动调整大小

In case it is relevant, the width of the first column of the TableLayout has is set to an Absolute size of 100 pixels, while the width of the second column of the TableLayout has been set to AutoSize.

任何人都可以摆脱任何光线为什么这种形式表现出乎我的意料,并就我怎么能得到这个工作在我想要的方式?任何帮助将是非常美联社preciated。

Can anyone shed any light on why this form is behaving contrary to my expectations and advise on how I can get this working in the way I want? Any help would be much appreciated.

推荐答案

在TableLayoutPanel中,似乎存储控制的初始大小和从来没有让他们更小,无论对接,锚固或任何其他值,如AutoSizeMode.GrowAndShrink。在设计师的对接控制的尺寸总会被储存,所以我发现最简单的方法是在InitializeComponent后,将宽度设置为0(因为控制停靠,也不会真正调整组合框,但它会允许所述的TableLayoutPanel使其小到设定宽度)

The tablelayoutpanel seems to store the initial size of the controls and never make them smaller regardless of docking, anchoring or any other values such as AutoSizeMode.GrowAndShrink. In designer the size of the docked control will always be stored, so the easiest method I've found is to set the width to 0 after the initializecomponent (since the control is docked, it won't actually resize the combobox, but it will allow the tablelayoutpanel to make it as small as the set width)

        InitializeComponent();
        comboField.Width = 0;

这篇关于放置在TableLayout停靠控件不会自动尺寸比他们的创作尺寸更小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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