I’m trying to change a panel to a specific form (as this is the only way I can fathom it) based on the selected TreeView node. For example, in Visual Studio, if you right-click on “Solution ‘solutionname’ (1 Project)”, click ‘Properties’, it comes up with a tree list on the left side. When you click on a selection, the right pane changes.
I’ve searched continuously for hours the previous few days and only found a tutorial showing how it can affect a webBrowser control.
This is a farfetched example that I can understand:
private void tree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
treeNode nName = e.Node;
//For testing:
string pg = "";
pg = nName.Tag;
if (pg == "Form2") display = Form2;
}
Display is a panel. I know this is absolutely wrong, but I couldn’t find any proper method using my search terms.
You will need to set
Visibleon all your panels tofalse, except for the one you want to display which will be set totrue.WinForms does not have any particularly nice way of setting this up. You could set the
Tagproperty of each node to be a reference to the panel (this has to be done programmatically – the designer won’t let you do it), then iterate through the entire tree view to set((Panel)node.Tag).Visible = falsefollowed by((Panel)e.Node.Tag).Visible = trueor you can maintain the list separately. If you don’t have many panels, a switch/if-else block may be okay, too.