473,396 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to create clone of Form


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

Jul 18 '06 #1
1 4378
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" <kn*******@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
>
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

Jul 18 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: scoobydoo | last post by:
Hello, I am trying to implement ICloneable's Clone() function, using Serialization. However, my code causes an exception. I have a class derived from TreeNode called "Node1". In Node1, I...
1
by: Semut | last post by:
Hello, When do I need to use the Clone function? I am aware that instances that inherited Forms.Control will somehow be of reference types instead of value types. I have tested that ArrayList...
0
by: Balu Ramachandran | last post by:
How can I create the Thumbnail view from the form? In the following approach I tried but Iams facing some limitations to get the thumbnail image of the form alone. Plaese any one can help in...
12
by: Doug Bell | last post by:
Hi, I am having problems trying to create a (temporary) DataTable from a selection from a DataGrid (dgOrders). dtOrdDetails is declared as a Public DataTable Sub is: Dim stFilter as String...
2
by: Jake Barnes | last post by:
Using javascript closures to create singletons to ensure the survival of a reference to an HTML block when removeChild() may remove the last reference to the block and thus destory the block is...
1
by: Alex D. | last post by:
hi guys. I need to clone multiple times an object and I am succesfully cloning using the regular serialization process, using a MemoryStream. My problem is that after cloning the object more that...
18
by: Sandra-24 | last post by:
Can you create an instance of a subclass using an existing instance of the base class? Such things would be impossible in some languages or very difficult in others. I wonder if this can be done...
16
by: Hamed | last post by:
Hello I am developing a utility to be reused in other programs. It I have an object of type Control (a TextBox, ComboBox, etc.) that other programmers use it in applications. they may set some...
4
by: WebNewsReader | last post by:
This one should be easy ;) How can I create a button control at runtime using one that is already created and adjust the properties ? Thanks in advance
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.