How to check if there is a Usercontrol in a Panel? C# Winforms

Asked

Viewed 164 times

0

I’m making an application that has a central Panel, and for it I’m controlling the Usercontrols, I’m using Clear, Add and Bringtofront to manipulate, i wonder if it has any function so that I can verify if a specific Usercontrol has already been added in my Panel, an example, in two different Usercontrols I add a same Usercontrol in the Panel, so I want that if I have already added, i don’t need to add again, I just give a Bringtofront because one of these two Usercontrols will already have added this new Usercontrol in the Panel, I want to do a check before giving the command Panel.Controls.Add()...

Hitching a ride on this question, do you have any method to remove only ONE Usercontrol from the Panel? Other than with Clear(), because it cleans the whole panel, then I would lose some information from other Usercontrols that have already been opened... I’m sorry if I’ve become too difficult to understand my doubt, I’d appreciate it if someone could help me.

1 answer

1

I looked for my doubt in English and found the right answers in Stack gringo.

Check if a Usercontrol is added to the Panel:

if(panel.Controls.Contais(myUserControl))
{

}

Remove a specific Usercontrol

panel.Controls.Remove(myUserControl);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.