2

I've got windows form app I'm developing, and my client wants a TreeView on the left with nodes that when clicked allow their users to work in detail screens on the right. The simplest approach was to create panels which are disabled until the appropriate node is clicked. However, this app is growing and way too much of it is living in the main form.

I'm wondering if it is possible to have one form per node that will open and expand into the detail area on the right, and then close when I am done with it. That way I don't have a single monolithic form, however I am not sure of how to go about that.

Anybody have any insight into how to do something like that?

Thanks.

Mike Malter
  • 1,018
  • 1
  • 14
  • 38

3 Answers3

1

You should try using UserControls.

Basically, each UserControl is a form (more or less) that you can add to your main form just like you would any other control.

zsalzbank
  • 9,685
  • 1
  • 26
  • 39
  • Thank you for this suggestion. I thought about user controls in the beginning, but shied away from them because it seemed I would have to write a lot of code exposing data, events and methods. However, the actual form has very little interaction with components outside of itself. So this seems like a good way to go now. One question, how do you manage sizing? Would you put the user control in a panel and then set it to doc in the parent container? – Mike Malter May 19 '11 at 16:43
  • i have a similar setup for an application I am working on. i have a splitcontainer with the treeview on the left and then on the right side, i add or remove the usercontrol. i always dock it to fill and have the anchors of the controls in the usercontrol set appropriatley – zsalzbank May 19 '11 at 17:25
  • What do you mean by anchor? Can you post a snippet? Thanks. – Mike Malter May 19 '11 at 17:50
  • controls all have an Anchor property that you can set to make the control expand to the size of the form, keeping the same distance from the sides of the parent container – zsalzbank May 19 '11 at 19:59
0

I would inherit from Panel for each page, attach an instance of each Panel-derived object to the Tag property of each TreeView node, and display that (Dock=Fill) when a node is selected.

Ry-
  • 218,210
  • 55
  • 464
  • 476
  • Thanks for your answer, however, I need to get away from panels because all the code for the panel is in that one form and I don't want that much code in one form. Much of the application is going to be driven by clicking an element in the TreeView which will display a UI in the detail area on the right. I need to break out these UI's into containers that are not in the same form. – Mike Malter May 19 '11 at 16:38
  • Read my answer again - you need to create classes that *inherit* from Panel, and use those in the form. – Ry- May 19 '11 at 17:59
  • Thank you for taking the time to respond to my comment. – Mike Malter May 20 '11 at 04:12
0

You can use split controls and load the forms right side but needs to arrange it correctly. As @codethis mentioned, usercontrol is best enough to handle these as their code is written separately. Just you need to pass the parameter (from node selection).

You may need to multiple user controls and place them in your form according to your screen changes.

AjayR
  • 4,169
  • 4
  • 44
  • 78