tags:

views:

283

answers:

1

Hi,

So i'm making a settings screen at the moment where i'll have a tree on the left then a panel on the right. The panel thats on screen will depend on what tree item is selected..

Just wondering how do I go about designing these panels and saving theme for use later on (runtime).

Do I need to go and draw them out etc. view code then copy into a class or something?

Thanks.

Sorry if my question is a bit vague but i'm not really sure what I want :-O

Thanks.

EDIT Yes, i'm looking to make a settings screen like the one found in Visual Studio. A tree on the left (explorer like) and then a new form layout for each tree node.

+1  A: 

You'll want to create UserControls instead of a Panel, it is easy to edit in the designer. Dock the tree view to the left and use code like this to select the active user control:

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
        treeView1.AfterSelect += new TreeViewEventHandler(treeView1_AfterSelect);
    }
    private UserControl mActivePanel;

    void treeView1_AfterSelect(object sender, TreeViewEventArgs e) {
        UserControl newPanel = null;
        switch (e.Node.Index) {
            case 0: newPanel = new UserControl1(); break;
            case 1: newPanel = new UserControl2(); break;
            // etc...
        }
        if (newPanel != null) {
            if (mActivePanel != null) {
                mActivePanel.Dispose();
                this.Controls.Remove(mActivePanel);
            }
            newPanel.Dock = DockStyle.Fill;
            this.Controls.Add(newPanel);
            this.Controls.SetChildIndex(newPanel, 0);
            mActivePanel = newPanel;
        }
    }
}
Hans Passant
Hi There, thanks for your reply but I am having a little trouble understanding what is going on here.Could you please elaborate or provide a link where I can read up more on this. Thanks.
Conor H
Add UserControls to your project, don't use Panels. I can't think of a good link for that. The code I posted is just the plumbing you need in the AfterSelect event handler to switch between user controls. Try it.
Hans Passant