views:

1257

answers:

4

I am creating a WinForm App(.net3.5) where I display some Client Details. My issue is that we have a directions field that correlates to an Address. To save room I would like to have the directions hidden until the user "wishes" to see them. My intended method was to have an "accordion" like presentation for the directions.
I would imagine I could also do this with a hidden field and BringToFront()(would this be better).

Can someone offer some guidance on the Accordion Style?
Does something already exist?
Do I need to take anything special into account?
In coding my own behavior; Would I just move everything down and then back up etc?

Thanks!

+1  A: 

I think you would want to group your associated controls together in panels, align them to the top/bottom of your form, and then programmatically show/hide the appropriate panel when the user clicks "More Detail >>" / "<< Less Detail".

EDIT: I don't know of a helper control for this specific functionality, aside from panels used to group controls and show/hide them all at once.

JMD
+1  A: 

If the controls are freely placed, then yes - you'd have to move things up or down. You can reduce the amount of work by encapsulating groups of related controls into panels: then you just have to move the panels. If the panels are docked (for example, "top") - then just hide / show the panel and everything should fall into place automatically.

Marc Gravell
Great minds think alike? Or fools seldom differ?
JMD
+4  A: 

The concept you are talking about is called Progressive Disclosure. Microsoft has some excellent tips in the UX Guide about these types of controls.

Matt Brunell
+1 for directing me to a useful resource. Thank You
Refracted Paladin
+2  A: 

When I require this type of behaviour, I find that the TableLayoutPanel is useful. You can set the rows and columns to auto-size if holding expandable content - that way, when you hide the content, the row collapses.

If you then have another control (a button, for example), you can use that to control the hidden state of the expandable content.

For example, create a 3 row, 1 column table. Add a fixed size button at the top, and an autosize element in the middle. Make the last row percentage-sized (you need this so that something takes the remaining space when the middle row sizes to zero). Then use your button to change the visible property of whatever you have in the middle row.

Jeff Yates
I like this approach but is there another step? As a test I created a 3 row 2 column table. Set the middle row to auto size and the item it contained to Visible=false. It is not collapsing that row as I would have expected. THanks!
Refracted Paladin
I've updated my response. The important part is to have one row set to percentage so that it steals the space of the auto-sized row. Also, everything in the auto-size row has to be hidden for it to work (you can't have something in the other column unless that is hidden as well).
Jeff Yates
Also, changing the middle item's Visible property in the WinForms designer will not show any change - the change occurs at runtime.
Jeff Yates