是否可以将一个控件锚定到另一个控件?
是否可以将一个控件锚定到另一个控件?
假设我希望 Button1 与 Textbox1 控件保持 4px 距离,而无需
使用 FlowLayoutTable 控件?
“为什么会有这样的优势?” - 有人可能会问
好吧,假设您有一个带有垂直拆分器的 SplitContainer
,并且您有 Textboxes
在 SplitContainer.Panel1
中,它们固定在左侧和右侧,但其最大尺寸
宽度小于您允许的 SplitContainer.Panel1's
宽度(也许
因为您希望文本显示在那里,或者因为额外的填充或其他什么,您可以命名它)
现在假设您在 Textbox1
旁边还有一个按钮,并且您不希望 Textbox1
是
与 Button1
重叠,因为它延伸得很远。
如果我想让我的文本框
以留有空间的方式填充SplitContainer.Panel1
Button1
控件,而它们仍然锚定在右侧,我该怎么做?
Is it possible to anchor a control to another control?
Lets say i want my Button1 to keep its 4px distance from Textbox1 control without
using FlowLayoutTable control?
"Why would be this advantageous?" - one could ask
Well let's say you have a SplitContainer
with a vertical splitter and you have Textboxes
in SplitContainer.Panel1
which are anchored to the left and right but their maximum size's
width is smaller than you allow to the SplitContainer.Panel1's
width to have (maybe
because you want text to show up there or because additional padding or whatever,you name it)
Now let's say you also have a button next to Textbox1
and you dont want Textbox1
to be
overlapped by the Button1
because its extends to far.
If i want to have my textbox
fill the SplitContainer.Panel1
in a fashion that it leaves space forButton1
control while still both of them are anchored to the right how would i do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我广泛使用 TableLayoutPanels 和 FlowLayoutPanels 来完成此任务。对于您的具体情况,我将使用一个 TableLayoutPanel,每个文本框包含三列和一行。
第 1 列:自动宽度,包含所有带有
AutoSize = True
的标签。第 2 列:100% 宽度,包含全部带有
Anchor = Left, Right
的文本框。第 3 列:自动宽度,包含相应行中的按钮。
接下来,我设置除按钮旁边的
ColumnSpan = 2
之外的所有文本框。然后只需将TableLayoutPanel放入SplitPanel中并设置Dock = Fill
即可。I extensively use TableLayoutPanels and FlowLayoutPanels to accomplish this. For you specific circumstance I would use a TableLayoutPanel with three columns and a row for each TextBox.
Column 1: Auto-width, contains Labels all with
AutoSize = True
.Column 2: 100% width, contains TextBoxes all with
Anchor = Left, Right
.Column 3: Auto-width, contains the Button in the appropriate row.
Next, I set all text boxes, except for the one next to the button,
ColumnSpan = 2
. Then just put the TableLayoutPanel in the SplitPanel and setDock = Fill
.这将是现场的一个序列,应该从左侧流出并继续工作,让右侧应该进行布局。
it will be a sequence in live which should be flow out from left and keep working lets the right side should be layout.