PC Review


Reply
Thread Tools Rate Thread

how to create clone of Form

 
 
Neeraj
Guest
Posts: n/a
 
      18th Jul 2006

hi
I want to make clone of current Form which is currently seen.I Used
attribute [Serializable] above the class declaration which extends
Form. Impleament the ICloneable interface and Make method which code is

public Object Clone()
{
return this.MemberwiseClone();
}
public static object DeepClone(
object obj)
{

object clone = null;
using (MemoryStream ms =
new MemoryStream())
{
BinaryFormatter bf =
new BinaryFormatter();
bf.Serialize(ms, obj);
ms.Position = 0;
clone = bf.Deserialize(ms);
}
return clone ;
}

but it generate SerializationException
which i show

Type 'System.Windows.Forms.Form' in Assembly 'System.Windows.Forms,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is
not marked as serializable.

At
bf.Serialize(ms, obj);
that Line.
any one have any idea regard this please share this.

with regards.
Neeraj

 
Reply With Quote
 
 
 
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      18th Jul 2006
Hi,

It's clear in the message Form is not serializable.

What is the purpose of this? If you just want to create another similar form
in the current app then you need to implement it by yourself. I have no idea
how difficult it will be, especially if you have a lot of controls , You
will have to iterate in the Controls collection and create the same controls
with the same properties.
If you want to recreate it in another machine ( or process ) instead of
creating the controls you should send the properties values and in the
receiving end you will have to reconstruct the form.


--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Neeraj" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> hi
> I want to make clone of current Form which is currently seen.I Used
> attribute [Serializable] above the class declaration which extends
> Form. Impleament the ICloneable interface and Make method which code is
>
> public Object Clone()
> {
> return this.MemberwiseClone();
> }
> public static object DeepClone(
> object obj)
> {
>
> object clone = null;
> using (MemoryStream ms =
> new MemoryStream())
> {
> BinaryFormatter bf =
> new BinaryFormatter();
> bf.Serialize(ms, obj);
> ms.Position = 0;
> clone = bf.Deserialize(ms);
> }
> return clone ;
> }
>
> but it generate SerializationException
> which i show
>
> Type 'System.Windows.Forms.Form' in Assembly 'System.Windows.Forms,
> Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is
> not marked as serializable.
>
> At
> bf.Serialize(ms, obj);
> that Line.
> any one have any idea regard this please share this.
>
> with regards.
> Neeraj
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot create Recordset Clone oldblindpew Microsoft Access Form Coding 4 7th Mar 2009 02:22 PM
Task Form: Unlock/clone/copy first page, or where to get prebuiltcustom form? alexw Microsoft Outlook Form Programming 5 2nd Jul 2008 10:43 PM
is there anyway to create a clone of an excel sheet in vba? Daniel Microsoft Excel Discussion 7 6th Jul 2005 10:10 PM
is there anyway to create a clone of an excel sheet in vba? Daniel Microsoft Excel Worksheet Functions 2 6th Jul 2005 09:41 AM
how do you create a datatable clone but with a different row count hs Microsoft ADO .NET 4 26th Aug 2003 08:34 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:36 AM.