Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding a panel should force controls below to move up and resize the form

Tags:

c#

.net

winforms

OK, this is driving me a bit nuts at this point. Time to ask the crowd:

I have a form that consists of: two vertical "halves" created by a SplitContainer. Inside the bottom "half" / SplitContainer panel... I have:

  1. A set of fields/controls for the user to fill out, contained within a panel.

  2. Below that, a panel containing buttons for "submit", "cancel"...and one that's "show/hide". This "show/hide" is intended to show/hide the panel I just described in point 1 above.

What I want to happen is: when the user clicks to "hide" the panel of controls, not only do those controls vanish, but also:

  • The panel containing the submit, cancel and show/hide buttons moves up (so that we don't have this big blank space where the now-hidden panel once was).
  • The form resizes itself vertically so as to make up for the now-hidden panel and the fact that we've moved the bottom controls upwards.

I have no problem getting the panel of controls/fields to show/hide. But I can't seem to figure out how to accomplish the other two tasks. I've tried various combinations of AutoSize, AutoSizeMode, and Dock options.

Any suggestions?

like image 677
DaveyBoy Avatar asked Jan 04 '16 15:01

DaveyBoy


People also ask

What is used to move and resize the controls on the form window?

By default, the controls on an Access form stay anchored to the upper-left corner of the form, and do not resize when you resize the form. To change this behavior, you can use the Anchoring command.

How do I resize a form control?

To resize multiple controls on a form In Visual Studio, hold down the Ctrl or Shift key and select the controls you want to resize. The size of the first control you select is used for the other controls.

Which control you would select to place the child control in top left right and bottom using dock property?

DockPanel defines an area to arrange child elements relative to each other, either horizontally or vertically. With DockPanel you can easily dock child elements to top, bottom, right, left and center using the Dock property.

Which layout control can set the property of control at run time?

The TableLayoutPanel control arranges its contents in a grid. Because the layout is done both at design time and run time, it can change dynamically as the application environment changes.


1 Answers

If you put all your controls into a FlowLayoutPanel where the children are arranged vertically, then hiding some controls should cause the "lower" controls to move up the page.

You might still need to write some code to resize the form itself once the optional content has been hidden or before it's shown.

like image 185
ChrisF Avatar answered Sep 18 '22 05:09

ChrisF