views:

147

answers:

1

when i click to a node in the treeview i want to see it's corresponding form in the splitcontainer.panel2,there have diffrent nodes and forms.if any one knows please help me

+2  A: 
Sub ShowFormInPanel(form as Form,panel as Panel)
Form.TopLevel = False

For Each Cont As Control In panel.Controls
    If Cont IsNot form Then Cont.Visible = False
Next

If Not panel.Controls.Contains(form) Then
    panel.Controls.Add(form)
    form.FormBorderStyle = Windows.Forms.FormBorderStyle.None
    form.Dock = DockStyle.Fill
    form.Show()
Else
    form.Visible = True
End If
End Sub

First you have to create an empty panel in the splitcontainer. and then In the "NodeClick" event of the treeview all you have to do is:

ShowFormInPanel(Form, Panel)

NOTE: Take care with memory, because this doesn't dispose closed forms, it just hides them.

Burnsys