How to add the same object to different Panels in c#?

112 Views Asked by At

I am new in c#, I was wandering why if I try to add the same object to different FlowLayoutPanel, it is displayed only on the last Panel.

Example:

Label noElementsTitleLabel = LabelFactory.getLabel("No elements");

private void loadLabelsInPanel(FlowLayoutPanel panel, Label title, Label[] labelArray)
{
    panel.Controls.Add(title);
    if (labelArray.Length == 0)
    {
        panel.Controls.Add(noElementsTitleLabel);
        return;
    }            
    panel.Controls.AddRange(labelArray);
}

If I call loadLabelsInPanel three times giving three different layout panels and labelArray is always empty, I can see the noElementsTitleLabel only in the third panel

0

There are 0 best solutions below