如何在调整Window大小时使控件可伸缩? [英] How make Controls scalable when resizing Window?

查看:102
本文介绍了如何在调整Window大小时使控件可伸缩?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

如何使我的控件相对于表单的大小可伸缩?

我的意思是,当表单上的面板的锚点设置为全部4时边框然后更改窗体大小时面板宽度/高度属性更改但面板的左/顶部位置是固定的而不是更改。当不正确的表格大小发生变化时,我必须设置哪些属性才能使面板的左/上位置移动?

问候,




div class ="h2_lin">解决方案

嗨Henk,

我并不完全理解你的问题。但我认为你不想在增加表单大小的同时拉伸你的面板,而是随着表单的右边和底边边框移动而远离顶部和左边框。如果是这种情况,只需将Panel控件的Anchor属性设置为right和bottom。

Anchor属性允许您将控件的四个边框中的任何一个或全部锚定到窗体的四个边框或父容器。因此,当您在顶部和底部锚定控件时,控件的顶部边框与窗体的顶部边框和控件的底部边框以及窗体的底部边框之间的距离将始终相同。为了保持距离,控件将自行伸展(在这种情况下,高度将增加/减少)。

我强烈建议您使用Anchor和Dock属性。起初他们似乎很难使用,但他们有时也很有帮助。它们有助于避免这么多编码。只需在这些属性上尝试不同的值并查看结果。


Hello,

How do I make my Controls scalable in relation to the size of the Form?

I mean, when the Anchors of a Panel on a Form are set to all 4 borders then the Panel Width/Height properties change when changing the Form size but the Left/Top position of the Panel is fixed and not changing. What properties do I have to set to what value to also make the Panel's Left/Top position move when the undelying Form size is changed?

Regards,

Henk

解决方案

Hi Henk,

I didn't exactly understand your problem. But I think you don't want to stretch your panel while increasing the size of the form but move along with the form's right and bottom borders away from top and left borders. If this is the case, just set the Anchor property of the Panel control to right and bottom.

The Anchor property allows you to anchor any or all of the four borders of your control to the four borders of the form or parent container. So, when you anchor a control on Top and Bottom, the distance between the Top border of control and the Top border of the form and Bottom border of the control and Bottom border of the form will always be same. And to maintain the distance, the control will stretch itself (Height in this case will be increased/decreased).

I strongly recommend you to play around with the Anchor and Dock properties. At first they seem difficult to use but they are really helpful at sometimes and tricky too. They help avoid so much coding. Just try different values on those properties and see the results.


这篇关于如何在调整Window大小时使控件可伸缩?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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