简体   繁体   English

调整 window 的大小时,如何很好地制作 label 和文本框布局?

[英]How to make a label and textbox layout nicely when window is resized?

I have a label and a textbox in my Winform.我的 Winform 中有一个 label 和一个文本框。 They are one line.它们是一条线。

在

What I want to do is to make the textbox always fill-in the available space between the label and the right border of the container, even when window is resized我想要做的是使文本框始终填充 label 和容器右边框之间的可用空间,即使 window 被调整大小

The label is set to be AutoSize because it has different width in different languages. label 设置为 AutoSize,因为它在不同语言中具有不同的宽度。

I tried the flow layout, and I also tried various combinations of dock/anchor in both elements, but still can't make it work.我尝试了流式布局,也尝试了两个元素中停靠/锚点的各种组合,但仍然无法使其工作。 If there is not simple solution (beside program coding resizing myself), is there a less optimal solution?如果没有简单的解决方案(除了程序编码调整自己的大小),是否有不太理想的解决方案? Thanks.谢谢。

if it's only those 2 elements that need to be auto-layouted try this:如果只有这两个元素需要自动布局,试试这个:

take a table layout panel with 2 columns and one row... your label goes in one cell, the textbox in the other... dock both elements (dock fill) and set the column the label is in to autosize取一个有 2 列和 1 行的表格布局面板...您的 label 进入一个单元格,文本框在另一个单元格中...停靠两个元素(停靠填充)并将 label 所在的列设置为自动调整大小

dock the whole panel to whatever element you want (probably your form)将整个面板停靠到您想要的任何元素(可能是您的表单)

you may want to add some padding to your label您可能想为您的 label 添加一些填充

I would put the controls in a panel.我会将控件放在面板中。 Set the panel to the appropiate height.将面板设置为适当的高度。 Set the label to autosize and dock it left.将 label 设置为自动调整大小并将其停靠在左侧。 Set the textbox dock to fill.将文本框停靠设置为填充。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM