How do I duplicate Panels or create new Panels?

0

I have a form, in that form I want to buy the purchased products and their characteristics in different panels, I mean, every time I add a new article I want a new panel created. I have tried to instantiate a new panel and give it the characteristics of an already created one, but when giving it Location, it moves the one that already had, and not the new one that it creates.

I think what I need is a for each, but I do not know how to implement it.

What I try to do is. My panel already created is called item, the item has 2 textbox, 1 textbox for article, and another for the feature (Large, medium, small).

Panel myNuevoPanel = new Panel();
myNuevoPanel = item;
myNuevoPanel.Location = new Point(40, 50);

When I try to do that, my item moves, and the new panel I try to create does not move.

    
asked by Enrique Uviñas Rodriguez 19.11.2017 в 02:26
source

1 answer

0

It is along this line:

myNuevoPanel = item;

If what you want to do is create a panel equal to the previous one, you must clone it, or copy the properties of the previous panel to the new panely and add the controls that it has inside the panel.

myNuevoPanel.Size = item.Size;
myNuevoPanel.Location = item.Location;
// etc

Remember that being types by reference, you are not really copying the item value, but assigning the reference, and therefore myNuevoPanel is a reference to item.

Edit: Another thing you can do is a UserControl or user control, which already has the textbox inside, so, instead of creating a new panel in your code, you create a new control of the type that you designed, but it's going to be a show to be creating a new panel and controls inside.

    
answered by 19.11.2017 в 19:50