Can a Form be set to Serializable?
My App keeps crashing ever time I attempt to serialize the form.
I was under the impression that Serialization could be used to easily save
all of my data. If the form can not be serialized, how to I save the
information on it? 6 1689
Serialization only works on classes that are decorated with the
Serializable() attribute. System.Windows. Forms.Form is not.
You cannot serialize a form (or a control, or other disposable resource) for
various reasons. Imagine if you serialized it to a file, then deserialized
it later into a form - what happens to the handles? What if an existing
control has an identical handle to one of the controls on the form you're
trying to deserialize?
The solution is to create a class that holds the data (and just the data)
that you want to save, and decorate that class with the serializable
attribute. You can then use that for saving/loading data on a form.
Kind Regards,
Alex
"jp2msft" <jp*****@discus sions.microsoft .comwrote in message
news:DD******** *************** ***********@mic rosoft.com...
Can a Form be set to Serializable?
My App keeps crashing ever time I attempt to serialize the form.
I was under the impression that Serialization could be used to easily save
all of my data. If the form can not be serialized, how to I save the
information on it?
Thanks Mr. Clark,
I guess that makes sense. It sure would have been nice if the entire state
of the form could magically have been saved (date ranges, form position &
size, query strings, and maybe query results).
Yuck. Now I have to grunt it out.
"Alex Clark" wrote:
Serialization only works on classes that are decorated with the
Serializable() attribute. System.Windows. Forms.Form is not.
You cannot serialize a form (or a control, or other disposable resource) for
various reasons. Imagine if you serialized it to a file, then deserialized
it later into a form - what happens to the handles? What if an existing
control has an identical handle to one of the controls on the form you're
trying to deserialize?
The solution is to create a class that holds the data (and just the data)
that you want to save, and decorate that class with the serializable
attribute. You can then use that for saving/loading data on a form.
Kind Regards,
Alex
"jp2msft" <jp*****@discus sions.microsoft .comwrote in message
news:DD******** *************** ***********@mic rosoft.com...
Can a Form be set to Serializable?
My App keeps crashing ever time I attempt to serialize the form.
I was under the impression that Serialization could be used to easily save
all of my data. If the form can not be serialized, how to I save the
information on it?
Hi,
There *might* be a more re-usable solution to your problem in the form of
Reflection.
You could use Reflection to identify all Read/Write properties on the form
in question (which would exclude Handle, along with a few others) and then
add them to a Dictionary object which you can then serialize. Simply
reverse the process for deserialization .
Don't forget though that things like the titlebar text will be serialized as
well - if you're using that for any kind of status indication, it may be a
gotcha. Also, if further down the line you opt to change the background
colour of your form, any saved data from the past will cause it to revert to
what it was before!
The above solution would only work for the form itself. If you wanted to do
it for everything on the form, you're looking at recursively drilling down
through each control contained within the form, and their controls, and so
on. Then you have to come up with a structured naming convention (like
"MyForm/MainPanel/OptionFrame/Panel3/ControlName.Tex t").
It really does start to get a bit ugly after a while, but depending on the
situation it could work out better for you than manually going through all
the properties you want. The danger is when you realise you only want to
store about a quarter of the form's read/write properties in the first
place, and that's when it might be a good idea to just bite the bullet and
do it yourself.
Cheers,
Alex Clark
"jp2msft" <jp*****@discus sions.microsoft .comwrote in message
news:89******** *************** ***********@mic rosoft.com...
Thanks Mr. Clark,
I guess that makes sense. It sure would have been nice if the entire state
of the form could magically have been saved (date ranges, form position &
size, query strings, and maybe query results).
Yuck. Now I have to grunt it out.
"Alex Clark" wrote:
>Serializatio n only works on classes that are decorated with the Serializable () attribute. System.Windows. Forms.Form is not.
You cannot serialize a form (or a control, or other disposable resource) for various reasons. Imagine if you serialized it to a file, then deserialized it later into a form - what happens to the handles? What if an existing control has an identical handle to one of the controls on the form you're trying to deserialize?
The solution is to create a class that holds the data (and just the data) that you want to save, and decorate that class with the serializable attribute. You can then use that for saving/loading data on a form.
Kind Regards, Alex "jp2msft" <jp*****@discus sions.microsoft .comwrote in message news:DD******* *************** ************@mi crosoft.com...
Can a Form be set to Serializable?
My App keeps crashing ever time I attempt to serialize the form.
I was under the impression that Serialization could be used to easily
save
all of my data. If the form can not be serialized, how to I save the
information on it?
Good food for thought.
Thanks for your help! I've got some stuff saving, and at least now I know
how to save the rest.
Regards,
Joe
"Alex Clark" wrote:
Hi,
There *might* be a more re-usable solution to your problem in the form of
Reflection.
You could use Reflection to identify all Read/Write properties on the form
in question (which would exclude Handle, along with a few others) and then
add them to a Dictionary object which you can then serialize. Simply
reverse the process for deserialization .
Don't forget though that things like the titlebar text will be serialized as
well - if you're using that for any kind of status indication, it may be a
gotcha. Also, if further down the line you opt to change the background
colour of your form, any saved data from the past will cause it to revert to
what it was before!
The above solution would only work for the form itself. If you wanted to do
it for everything on the form, you're looking at recursively drilling down
through each control contained within the form, and their controls, and so
on. Then you have to come up with a structured naming convention (like
"MyForm/MainPanel/OptionFrame/Panel3/ControlName.Tex t").
It really does start to get a bit ugly after a while, but depending on the
situation it could work out better for you than manually going through all
the properties you want. The danger is when you realise you only want to
store about a quarter of the form's read/write properties in the first
place, and that's when it might be a good idea to just bite the bullet and
do it yourself.
Cheers,
Alex Clark
"jp2msft" <jp*****@discus sions.microsoft .comwrote in message
news:89******** *************** ***********@mic rosoft.com...
Thanks Mr. Clark,
I guess that makes sense. It sure would have been nice if the entire state
of the form could magically have been saved (date ranges, form position &
size, query strings, and maybe query results).
Yuck. Now I have to grunt it out.
"Alex Clark" wrote:
Serialization only works on classes that are decorated with the
Serializable() attribute. System.Windows. Forms.Form is not.
You cannot serialize a form (or a control, or other disposable resource)
for
various reasons. Imagine if you serialized it to a file, then
deserialized
it later into a form - what happens to the handles? What if an existing
control has an identical handle to one of the controls on the form you're
trying to deserialize?
The solution is to create a class that holds the data (and just the data)
that you want to save, and decorate that class with the serializable
attribute. You can then use that for saving/loading data on a form.
Kind Regards,
Alex
"jp2msft" <jp*****@discus sions.microsoft .comwrote in message
news:DD******** *************** ***********@mic rosoft.com...
Can a Form be set to Serializable?
My App keeps crashing ever time I attempt to serialize the form.
I was under the impression that Serialization could be used to easily
save
all of my data. If the form can not be serialized, how to I save the
information on it?
Other possibilities:
(1) Use databinding to bind you form controls to a data set
or
(2) Write a class that is based off the
System.Componen tModel.IExtende rProvider class to provide serialisation
options to all the controls on a form
or
(3) Write an extension method for the Control class
"jp2msft" <jp*****@discus sions.microsoft .comwrote in message
news:F6******** *************** ***********@mic rosoft.com...
Good food for thought.
Thanks for your help! I've got some stuff saving, and at least now I know
how to save the rest.
Regards,
Joe
"Alex Clark" wrote:
>Hi,
There *might* be a more re-usable solution to your problem in the form of Reflection.
You could use Reflection to identify all Read/Write properties on the form in question (which would exclude Handle, along with a few others) and then add them to a Dictionary object which you can then serialize. Simply reverse the process for deserialization .
Don't forget though that things like the titlebar text will be serialized as well - if you're using that for any kind of status indication, it may be a gotcha. Also, if further down the line you opt to change the background colour of your form, any saved data from the past will cause it to revert to what it was before!
The above solution would only work for the form itself. If you wanted to do it for everything on the form, you're looking at recursively drilling down through each control contained within the form, and their controls, and so on. Then you have to come up with a structured naming convention (like "MyForm/MainPanel/OptionFrame/Panel3/ControlName.Tex t").
It really does start to get a bit ugly after a while, but depending on the situation it could work out better for you than manually going through all the properties you want. The danger is when you realise you only want to store about a quarter of the form's read/write properties in the first place, and that's when it might be a good idea to just bite the bullet and do it yourself.
Cheers, Alex Clark
"jp2msft" <jp*****@discus sions.microsoft .comwrote in message news:89******* *************** ************@mi crosoft.com...
Thanks Mr. Clark,
I guess that makes sense. It sure would have been nice if the entire
state
of the form could magically have been saved (date ranges, form position
&
size, query strings, and maybe query results).
Yuck. Now I have to grunt it out.
"Alex Clark" wrote:
Serializatio n only works on classes that are decorated with the Serializable () attribute. System.Windows. Forms.Form is not.
You cannot serialize a form (or a control, or other disposable resource) for various reasons. Imagine if you serialized it to a file, then deserialized it later into a form - what happens to the handles? What if an existing control has an identical handle to one of the controls on the form you're trying to deserialize?
The solution is to create a class that holds the data (and just the data) that you want to save, and decorate that class with the serializable attribute. You can then use that for saving/loading data on a form.
Kind Regards, Alex "jp2msft" <jp*****@discus sions.microsoft .comwrote in message news:DD******* *************** ************@mi crosoft.com...
Can a Form be set to Serializable?
My App keeps crashing ever time I attempt to serialize the form.
I was under the impression that Serialization could be used to
easily
save
all of my data. If the form can not be serialized, how to I save the
information on it?
Hi Mr. Jones,
I'd be interested in hearing more about these ideas, especially #2 and #3.
Are there tutorials on these techniques someplace?
"Duncan Jones" wrote:
Other possibilities:
(1) Use databinding to bind you form controls to a data set
or
(2) Write a class that is based off the
System.Componen tModel.IExtende rProvider class to provide serialisation
options to all the controls on a form
or
(3) Write an extension method for the Control class
"jp2msft" <jp*****@discus sions.microsoft .comwrote in message
news:F6******** *************** ***********@mic rosoft.com...
Good food for thought.
Thanks for your help! I've got some stuff saving, and at least now I know
how to save the rest.
Regards,
Joe
"Alex Clark" wrote:
Hi,
There *might* be a more re-usable solution to your problem in the form of
Reflection.
You could use Reflection to identify all Read/Write properties on the
form
in question (which would exclude Handle, along with a few others) and
then
add them to a Dictionary object which you can then serialize. Simply
reverse the process for deserialization .
Don't forget though that things like the titlebar text will be serialized
as
well - if you're using that for any kind of status indication, it may be
a
gotcha. Also, if further down the line you opt to change the background
colour of your form, any saved data from the past will cause it to revert
to
what it was before!
The above solution would only work for the form itself. If you wanted to
do
it for everything on the form, you're looking at recursively drilling
down
through each control contained within the form, and their controls, and
so
on. Then you have to come up with a structured naming convention (like
"MyForm/MainPanel/OptionFrame/Panel3/ControlName.Tex t").
It really does start to get a bit ugly after a while, but depending on
the
situation it could work out better for you than manually going through
all
the properties you want. The danger is when you realise you only want to
store about a quarter of the form's read/write properties in the first
place, and that's when it might be a good idea to just bite the bullet
and
do it yourself.
Cheers,
Alex Clark
"jp2msft" <jp*****@discus sions.microsoft .comwrote in message
news:89******** *************** ***********@mic rosoft.com...
Thanks Mr. Clark,
I guess that makes sense. It sure would have been nice if the entire
state
of the form could magically have been saved (date ranges, form position
&
size, query strings, and maybe query results).
Yuck. Now I have to grunt it out.
"Alex Clark" wrote:
Serialization only works on classes that are decorated with the
Serializable() attribute. System.Windows. Forms.Form is not.
You cannot serialize a form (or a control, or other disposable
resource)
for
various reasons. Imagine if you serialized it to a file, then
deserialized
it later into a form - what happens to the handles? What if an
existing
control has an identical handle to one of the controls on the form
you're
trying to deserialize?
The solution is to create a class that holds the data (and just the
data)
that you want to save, and decorate that class with the serializable
attribute. You can then use that for saving/loading data on a form.
Kind Regards,
Alex
"jp2msft" <jp*****@discus sions.microsoft .comwrote in message
news:DD******** *************** ***********@mic rosoft.com...
Can a Form be set to Serializable?
My App keeps crashing ever time I attempt to serialize the form.
I was under the impression that Serialization could be used to
easily
save
all of my data. If the form can not be serialized, how to I save the
information on it? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: MAY |
last post by:
Hi,
I have a problem about serialize the form controls. I wrote a test program
to test serialize a from but fail (->An unhandled exception of type
'System.Runtime.Serialization.SerializationException' occurred in
mscorlib.dll) . Thx in advance. Here is the part of the code:
Regards
MAY
|
by: Richard Bysouth |
last post by:
Hi
When attempting to view inherited forms in design mode I have been getting
the message "The path is not of a legal form" and am unable to view the
designer.
I can't seem to find any further information on this error - does anyone
know what the problem and resolution might be?
thanks
|
by: --== Alain ==-- |
last post by:
Hi,
I've created a Form just for testing purposes.
on this form i have a custom control that i created.
Every time that i update my custom control (dll file), my test form
displays the following message :
"One or more errors encountered while loading the designer. The errors
are listed below. Some errors can be fixed by rebuilding your project,
|
by: Alan T |
last post by:
I got this kind of error recently:
When I tried to open a form I got error something like this:
One of more errors encountered while loading the designer. The errors are
listed below. Some errors can be fixed by rebuilding your project, while
others may require code changes.
Look at the lines all are referencing the system things such as
at System.Reflection.Module.GetTypesInternal(StackCrawlMark& stackMark)
|
by: ThunderMusic |
last post by:
Hi,
I have a custom form that works fine when I debug it or run it in release
mode but cannot be loaded in the designer... Actually, it can be loaded in
the designer when no control is on it, but the resizing tool (in the
designer) is offset both horizontally and vertically and when I put a
control on it, as soon as I save, the designer throws an exception (but
cannot be reproduced everytime) and the form cannot be loaded anymore unless...
| |
by: Marc |
last post by:
The first part of the below writes the name and location of all
buttons on a from to a text file. The second part reads that
information back in and recreates the buttons. My problem is reading
the location value back in where I marked ?????????????????????. As it
wont accept a string value?
Private Sub Save_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Save.Click
|
by: iKiLL |
last post by:
Hi All
I am Developing in C# with VS2005. I am Developing a Windows Mobile Forms
Application with the CF2
My problem is that when the Input panel is displayed my screen does not
|
by: =?Utf-8?B?RjVGNUY1?= |
last post by:
I have created a control by inheriting ToolStripMenuItem that has an image
property called LargeImage.
------
public class EventSubMenuItem : ToolStripMenuItem
{
private Image _largeImage = null;
|
by: =?Utf-8?B?QnJhZA==?= |
last post by:
i dont understand this behaviour...
i open a vb form i created and want to save it as a new name and make some
changes
when i do (in vs2005) the original form looses its ui
whats up with that??? it turned into a straight class
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |