WINDOWS FORMS APPLICATION : CSWinFormObjPersistence Project Overview


The Object Persistance sample demonstrates how to persist an object's data
between instances, so that the data can be restored the next time the object
is instantiated.


1. Build the solution and run.
2. Enter some value to Name, Age, Address field
3. Close the form.
4. Run the app again. You can see these value keeps in the field.

Code Logic:

This sample uses a binaray file "Customer.bin" to store the information.

1. Create a class names Customer with some properties, and make the whole class
  as serializable by adding the Serializable attribute on top of the class
  If you do not want to persist a field, mark it as NonSerialized.

2. In the Form.Load event,check if the Customer.bin file exists, it the file
  exists, use BinaryFormatter.Deserialize method to retrieve the data stored
  in it, otherwise create a new instance of Customer class.
3. In the Form.FormClosing event,use BinaryFormatter.Serialize method to
  serialize the customer information to the Customer.bin file.


1. Walkthrough: Persisting an Object in Visual Basic .NET
2. Windows Forms General FAQ.