简体   繁体   English

调整窗口大小时如何使控件伸缩?

[英]How to make controls stretch and shrink when the window is resized?

调整窗口大小时,如何使所有控件都不在一个角上或只是耸耸肩,而是变得更大或更小以与窗口相对应?

You need to Anchor your control(s) on the window. 您需要在窗口上Anchor控件。

Basically u (always) anchor your control on Top & Left (that's default anyway). 基本上,您(始终)将控件固定在“ Top和“ Left (无论如何都是默认设置)。

If you want to stretch your Control horizontal add Right . 如果要拉伸水平Control添加Right For vertical stretching add Bottom . 对于垂直拉伸,请添加Bottom

[Properties] (rightclick the control you want to anchor and select properties) [属性] (右键单击要锚定的控件并选择属性)

在此处输入图片说明

Use Anchor property of each control to achieve the effect. 使用每个控件的Anchor属性可达到效果。

For example, if you set it to "Right, Bottom" on a control, it will keep its right and bottom side anchored (set to fixed distance) against the right and bottom edge of the form. 例如,如果在控件上将其设置为“ Right,Bottom”,它将使其右侧和底部固定在表单的右侧和底部边缘(设置为固定距离)。

This is sufficient for basic sizing. 这对于基本大小确定就足够了。 For advanced sizing, you have to size your controls manually on window resize event. 对于高级调整大小,您必须在窗口调整大小事件上手动调整控件的大小。

You might also want to set MinimumSize property of your form to prevent its window to shrink under that size. 您可能还需要设置表单的MinimumSize属性,以防止其窗口缩小到该大小以下。 This way you can prevent unwanted layout distortions like controls clipped or completely hidden behind right or bottom edge of the window. 这样,您可以防止不必要的布局失真,例如控件被裁剪或完全隐藏在窗口的右边缘或底边缘之后。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WPF 在调整窗口大小时使拉伸的 TextBlock 收缩 - WPF make a streched TextBlock shrink when window is resized 调整 window 的大小时,如何很好地制作 label 和文本框布局? - How to make a label and textbox layout nicely when window is resized? 调整父窗口大小时自动调整用户控件的大小 - Automatic resizing of user controls when parent window is resized 当 Horizo​​ntalAlignment 和 Horizo​​ntalContentAlignment 不起作用时,如何使 WPF 中的控件拉伸以填充可用宽度? - How can I make controls in WPF stretch to fill available width when HorizontalAlignment and HorizontalContentAlignment don't work? 调整wpf窗口大小时如何重新加载工具栏 - How to reload the toolbar when the wpf window is resized 调整 window 或容器大小时如何修复滚动条? - How to fix scrollbars when the window or container is resized? 调整PictureBox大小时如何移动矩形 - How to make a rectangle move when PictureBox is resized 调整窗口大小时,锚定控件不会调整大小(56k注意) - Anchored controls won't resize when window is resized (56k beware) 调整窗口大小时图像被裁剪 - The image is cropped when the window is resized 在C#中调整窗口大小时如何保持对象到位 - how to keep objects in place when window is resized in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM