Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello,

I am Trying to Clone a Form.
When i am using serialization. It copies all the members but doesnt open a new Form.
What i here want is to create a exact replica of the form i.e a new Form
C#
Form1 Frm1= new Form1();
Form1 Frm2= Frm1.MemberwiseClone();
Frm2.Show();

The Above mention code does Create a new Object but refers to the previous object i.e Frm1.

I used another Function

C#
Form1 Frm2= Clone() as Form1;
 public object Clone()
        {

            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream stream = new MemoryStream();
            formatter.Serialize(stream, this);
            stream.Seek(0, SeekOrigin.Begin);
            this.MemberwiseClone();
            return (Form1)formatter.Deserialize(stream);

        }
This Code Creates the new object but doesnt copy the Data.

Please help!!!

Kind Regards
Posted
Updated 11-Mar-15 23:55pm
v4
Comments
CHill60 12-Mar-15 5:41am    
We can't see your screen, access your HDD or read your mind. Without seeing some code we can't help you find out what the problem is.
Use the Improve question widget to post the code you are having a problem with
nikita2410 12-Mar-15 5:54am    
Please refer the question again. have updated it
Mehdi Gholam 12-Mar-15 5:47am    
Why? Just clone the data and open the form with that.
nikita2410 12-Mar-15 5:52am    
How???
Mehdi Gholam 12-Mar-15 5:55am    
Create a data container class and bind your form to the properties of that class (basic model-view implementation).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900