0
votes

i have a main form which is containing a menu. when i click a menu button there is an usercontrol is loading panel control in main form:

splitContainerControl1.Panel2.Controls.Add(new Moduller.userControlStokListesi() { 
    Dock = DockStyle.Fill 
});

And there is a form on UserControl. when a user fill that form and hit the save button i want to remove that user control form from panel control.

How can i do that?

1

1 Answers

1
votes

So if I understand your question correct, you want to remove the instance of Moduller.userControlStokListesi from the Panel2 ?

There are several ways to achieve this. You can remove all controls from a panel this way:

splitContainerControl1.Panel2.Controls.Clear();

You can also remove specific items:

splitContainerControl1.Panel2.Controls.RemoveByKey("the key of your control");

Or if you want the user control removes itself from the panel, you can call this snippet within the user control instance:

SplitContainerControl splitPanel = (SplitContainerControl) this.Parent;
splitPanel.Panel2.Controls.Remove(this);