There is:
- UserControl_1;
- UserControl_2;

How to make that when moving through the nodes of the tree, depending on the selected node, in "panel1" displayed "UserControl_1" or "UserControl_2"?
I did as shown in the code below.
Will it be right?

private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { string name = e.Node.Text; switch (name) { case "Node_1": UserCntrl_1 userCntrl_1 = new UserCntrl_1(); panel1.Controls.Clear(); panel1.Controls.Add(userCntrl_1); break; case "Node_2": UserCntrl_2 userCntrl_2 = new UserCntrl_2(); panel1.Controls.Clear(); panel1.Controls.Add(userCntrl_2); break; } } 

enter image description here

  • Yes, it will be right - Igor
  • @Igor After selecting "Node_1", the user selects "Node_2". Do you need to do something with "userCntrl_1"? If any processes are running there, will they continue to work? - eusataf
  • Yes, they will continue. Processes should take into account that the control at any time may not become a parent. - Igor
  • @Igor Then maybe you need to kill after moving to the next node the processes of the previous node (form)? How to do it? - eusataf
  • I would not remove the UserControl from the collection, but simply change the Visible property, but you can. Internal processes to bind to the state properties Visible (true / false) or Parent (null /! Null), something like that. But in general, the processes should not be nailed to the control, they have a place in the model layer, and let the control reflect to itself the state and does not do unnecessary things. - rdorn

0