Search code examples
winformsmdimdichild

.NET - Correct UI Structure


I'm working on a C# application's UI that has the following structure:

Main Form (MDI Parent)

  • Tree View
  • Multiple MDI Childdren, each containing:
    • Custom User Control

I'd like to separate the form's canvas space allocated for the Tree View from that where the MDI Children are allowed to move in. To that extent, I tried a SplitContainer and setting the MDI Child's TopLevel field to 'false', but, besides the fact that newly created MDI Children were created behind the old ones, I also had issues with them not being cleared properly from the screen and other weird issues.

As I don't have lots of experience with UIs in C#, is the path I am taking correct? Would it be easier to change the above structure so that it doesn't use MDI anymore, or is there a simpler way of dividing the canvas between the tree view and the MDIs, other than the SplitContainer?

Cheers, Alex


UPDATE: Actually, the solution seems to work quite nicely, thanks! I'll probably be able to stop the widgets from moving in the wrong place by placing a simple check.

Besides that, is there any way in which I could make the TreeView resizable without involving a SplitContainer (because of the reasons mentioned in the post)?


Solution

  • Add a Panel to your Main Form and Dock it to the Left. Now add your TreeView to the Panel. Resize the Panel as necessary. Now your MdiChildren will take up the empty space to the right of the Panel...

    *You can actually simply Dock the TreeView itself to the Left side of the Form, but the Panel approach would allow you to place other controls in that left side area as well. Just depends on your UI layout.