Question

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?

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

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.

Was it helpful?

Solution

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;
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top