开发者

How can I organize controls on a form relative to one another and the form itself?

I have a child form in a MDI Windows Forms application. It has two controls: a Co开发者_开发技巧mboBox 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:

  1. When changing the size of the form, a width of both controls must be equal to the width of the form.
  2. The height of the TreeView must be changing to fill all free space of the form.


You can do like this:

  1. In the forms designer, layout the controls like you want them to look
  2. Select the ComboBox, and set the Anchor property to Top, Left and Right
  3. Select the TreeView and set the 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:

How can I organize controls on a form relative to one another and the form itself?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜