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:
You can do like this:
Anchor
property to Top, Left and Right Anchor
property to Top, Left, Right, and Bottom 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 with Dock=Fill
:
If you resize the form, the Combobox width and TreeView width/height will be resized accordingly, which suits your specific requirements.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.