Link to home
Start Free TrialLog in
Avatar of avinash_takale
avinash_takale

asked on

How to copy panels in C#

Hi Experts,

I need some help from you.

I am creating one application in which i want to create bunch og control in a panel and that same panel I want to copy not Move to some other location
When I copy then there will be two panel but unfortunately there is only one panel with different location.

Please provide me solution ASAP.

Thanks
-Avinash
Avatar of strickdd
strickdd
Flag of United States of America image

What you need to do is Create a new panel where you want the "copy" to be. Then you do a loop to copy the other controls i.e. (this is somewhat pseudocode)


//Create new panel in specific location

ForEach Control in OriginalPanel.GetControls()
    ControlCopy = Control;
    ControlCopy.ID = Control.ID + "Copy";

     PanelCopy.Controls.Add(ControlCopy);
Next


This should create copies of all the controls into the new panel and keep their original ID's, but append "Copy" to then end. The reason you have to append this is because you cannot have two controls of the same name in one form.
Avatar of avinash_takale
avinash_takale

ASKER

thanks a lot


but can you explain if panel one contains one text box and i want to create another panel i.e. panel2 at runtime with same content as panel 1.
can give me some more detail regarding how to code
please........
give me code its reallly urgent.

thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of strickdd
strickdd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry to say but the PlaceHolder control works with Webform and not with windows form
so can you tell me other alternative.

Really helpful this code for me.

-Avinash
Sorry about that, in that case you can use the Position property of the Panel. This will specify the X,Y coordinates of where to place the Panel on the screen and you can drop out all occurences of the placeholder from my code.