Hide a groupbox and also remove the space where it was present in winform
In my winform, I have three group boxes, based on selection of the items in a combobox the second group box(at the center) is hidden using grou开发者_如何学Gopbox.visible property. The problem is when the second goupbox is hidden, there seems to be an empty space in the area of the hidden group box, I want to move the third group box to the place where second group box is present. Can I use any other control instead of group box?
You could manually set Location
and Size
properties of your third groupbox or (I think better) set Dock
property of both groupboxes to Top
, so when your second gb becomes not visible, the third should scroll up to occupy free space.
You have a small number of options, assuming you are using just the default VS controls.
If you place these group boxes in a flow layout panel, when you make it invisible the layout panel will move other controls into it's previously occupied space.
If you dock the group boxes, making one invisible causes the others to occupy the space if the docking dictates.
If you cannot use layout mechanisms or controls, your only option is to modify the location or size of neighbouring controls to fill the space manually.
I very much advise trying to use the layout containers, or find a container online that handles the positioning for you. Position code buried in the form using potentially lots of "magic" numbers is definitely not maintainable.
you should solve it by chaning control that you're groupboxes
are in. Their position can't be set to constants. The other solution is to change position of third groupbox
when you change visibility of the second one.
A FlowLayoutPanel
should work http://msdn.microsoft.com/en-us/library/system.windows.forms.flowlayoutpanel.aspx
精彩评论