vb.net 在设计视图中制作响应式表单(非以编程方式)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37806229/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Make a responsive form in design view (not programmatically)
提问by mzurita
I am doing a WinForms program which should have a fully responsive design in a full screen.
我正在做一个 WinForms 程序,它应该在全屏中具有完全响应式的设计。
I get an approach which works more or less well. It consists into calculate a ratio between display screen and original form size. Then I apply this ratio to the width, left, height, top properties of each control inside the form.
我得到了一种或多或少有效的方法。它包括计算显示屏幕和原始表格大小之间的比率。然后我将这个比率应用到表单内每个控件的宽度、左侧、高度、顶部属性。
My doubt is about to use a native way for doing this, since, using anchors, the controls keep their same distances with parent control borders, but I doesn't do proportionally, for instance:
我的疑问是要使用本机方式来执行此操作,因为使用锚点,控件与父控件边框保持相同的距离,但我没有按比例进行操作,例如:
Form with 100x100 Button 20x20 located in (10,10)
带有 100x100 按钮 20x20 的表单位于 (10,10)
If I resized the form to 200x200 (multiply by 2), the best approach I can do in design view is keeping the four anchors to the button, so button size will be 120x120 at the same position (10,10), while what I need is a button with size 40x40, at position (20,20), since form size was multiply by 2.
如果我将表单的大小调整为 200x200(乘以 2),我在设计视图中可以做的最好的方法是将四个锚点保持在按钮上,因此按钮大小将是 120x120 在同一位置(10,10),而我需要一个大小为 40x40 的按钮,位于位置 (20,20),因为表单大小乘以 2。
Is it possible with winforms native operations in design view? (Avoiding to make calculations)
是否可以在设计视图中使用 winforms 本机操作?(避免进行计算)
回答by Martin Verjans
Yes it is possible.
对的,这是可能的。
Using the Property Dock = Fillyou can ask for a component to take all the room in its container.
使用该属性,Dock = Fill您可以要求一个组件占据其容器中的所有空间。
Now using a TableLayoutPanel, you can define cells to put your components in. And giving cell a percentage size, you can make sure the sizes will change when the form is resized...
现在使用 a TableLayoutPanel,您可以定义单元格以放置您的组件。并为单元格指定百分比大小,您可以确保在调整表单大小时大小会发生变化......
Here are more information on these things :
以下是有关这些内容的更多信息:

