开发者

C# How to design panel for later use..(Settings screen)

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 o开发者_Go百科n 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.


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;
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜