如何相对于彼此以及表单本身来组织表单上的控件?
我在 MDI Windows 窗体应用程序中有一个子窗体。它有两个控件:一个 ComboBox 和一个 TreeView,最后一个控件位于第一个控件下面。两个控件具有相同的宽度。如何设置它们和表单属性以实现以下目的:
- 更改表单大小时,两个控件的宽度必须等于表单的宽度。
- TreeView 的高度必须更改以填充表单的所有可用空间。
I have a child form in a MDI Windows Forms application. It has two controls: a ComboBox and a TreeView, with the last one under the first one. Both controls have the same width. How can I set up them and form properties to achieve the following:
- When changing the size of the form, a width of both controls must be equal to the width of the form.
- The height of the TreeView must be changing to fill all free space of the form.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以这样做:
Anchor
属性设置为 Top、Left 和 RightAnchor
属性到顶部、左侧、右侧和底部You can do like this:
Anchor
property to Top, Left and RightAnchor
property to Top, Left, Right, and Bottom基本上,您需要对接控件。使用Dock 您的两个控件的属性,以找到适合您的要求的“对接”。
下面是一个示例,演示了带有
Dock=Top
的 Combobox 和带有Dock=Fill
的 TreeView:如果调整表单大小,组合框宽度和TreeView宽度/高度将相应调整大小,以满足您的具体要求。
Basically, you would need to dock your controls. Play with the Dock property of your both controls to find the "docking" which suits your requirements.
Here is an example which demonstrates a Combobox with
Dock=Top
and TreeView withDock=Fill
:If you resize the form, the Combobox width and TreeView width/height will be resized accordingly, which suits your specific requirements.
这是通过
Anchor
属性完成的。在所有控件(组合框、树视图和用户控件)上正确设置它,它会按照您喜欢的方式拉伸。Dock
属性类似,但它也会影响位置,甚至在表单设计器中也会将控件“粘合”到其位置。This is done by the
Anchor
property. Set it properly on all controls (combobox, treeview and usercontrol) and it will stretch however way you like.The
Dock
property is similar, but it also affects location and kinda "glues" the control to its place even in the form designer.