C # How to create a panel for future use .. (Settings screen)

So, I am making the settings screen at the moment when I have the tree on the left, and then the panel on the right. The panel that is displayed on the screen will depend on which element of the tree is selected.

It’s just interesting how I get started designing these panels and saving the theme for later use (runtime).

Do I need to go pull them, etc. View code and then copy to class or something else?

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

EDIT Yes, I'm looking to create a settings screen similar to the one found in Visual Studio. The tree on the left (for example, explorer), and then a new form layout for each node tree.

+3
source share
1 answer

You want to create UserControls instead of Panel, it is easy to edit it in the designer. Prove the tree structure on the left and use this code 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;
        }
    }
}
+2
source

Source: https://habr.com/ru/post/1730597/


All Articles