samedi 14 mars 2015

Check if TableLayoutPanel contains instance?

I would like to check if a TableLayoutPanels already contains an instance of a UserControl but it don't works like this. mainActiveContr != userControl are both an instance of the AddEntryControl so shouldn't it be false? It's true ... Contains also seems to return true, but shouldn't it return false??



private UserControl mainActiveContr;

private void IsUserControlAlreadyActive(UserControl userControl)
{
if (!tableLayoutPanel1.Contains(userControl) && mainActiveContr != userControl)
this.tableLayoutPanel1.Controls.Add(userControl, 3, 2);

}


If someone clicks on of the buttons i create an instance of the UserControl and then i would like to check it.



AddEntryControl formChild1 = new AddEntryControl();
IsUserControlAlreadyActive(formChild1);

Aucun commentaire:

Enregistrer un commentaire