how to serialize a form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?Q2VjY28gKElUQSk=?=

    how to serialize a form

    Hi all,
    I need to know if there's a way to serialize a windows form. I included the
    [serializable()]/<serializable in the "myclassfor m" declaration, but I
    received an error because the windows.form class isn't marked as serializable.

    I can't access the windows.form class so... Any Ideas??

    Thank in advance and sorry if I made some mistakes

    Cecco
  • Phill W.

    #2
    Re: how to serialize a form

    Cecco (ITA) wrote:
    I need to know if there's a way to serialize a windows form.
    (1) Why?
    Forms contain lots and /lots/ of data that you probably won't care about
    when serializing it.
    I included the [serializable()]/<serializable in the "myclassfor m" declaration, but I
    declaration, but Ireceived an error because the windows.form class isn't marked
    as serializable.
    And there's probably a Good Reason for that (see (1)).

    What are you trying to /achieve/?
    If you want to save the Form's data then create a class to hold the data
    and teach that class how to save (and reload) itself.

    Regards,
    Phill W.

    Comment

    • =?Utf-8?B?Q2VjY28gKElUQSk=?=

      #3
      Re: how to serialize a form

      (1) Why?
      Because I need to compare two forms with "equals" method.

      My intent is to determine, every time, if a user modified the form, althoug
      if he decided to change a data value and then undo the operation.

      If I stored data in a struct when the users undo the operation the begining
      struct and the newone will be equals.

      So, I think, but i'm not sure, if I can have a deep copy of a form at the
      begining with "equals" method I can know if someone has modified in some case
      the form, also if the datas remain the same.

      "Phill W." wrote:
      Cecco (ITA) wrote:
      >
      I need to know if there's a way to serialize a windows form.
      >
      (1) Why?
      Forms contain lots and /lots/ of data that you probably won't care about
      when serializing it.
      >
      I included the [serializable()]/<serializable in the "myclassfor m" declaration, but I
      declaration, but Ireceived an error because the windows.form class isn't marked
      as serializable.
      >
      And there's probably a Good Reason for that (see (1)).
      >
      What are you trying to /achieve/?
      If you want to save the Form's data then create a class to hold the data
      and teach that class how to save (and reload) itself.
      >
      Regards,
      Phill W.
      >

      Comment

      • =?Utf-8?B?Q2VjY28gKElUQSk=?=

        #4
        Re: how to serialize a form

        Thanks Chuck.

        "Chuck" wrote:
        I think you might want to look into windows forms databinding in either MSDN
        or on Codeproject. You need to to detect changes in the underlying
        datasource, not the form itself. For example, datatables have built in
        events that fire when column values change.
        >

        >
        And built in methods to cancel changes made by the user:
        >
        Rolls back all changes that have been made to the table since it was loaded, or the last time AcceptChanges() was called.

        >
        If you are directly binding business objects to the form, then you can build
        dirty detection into your classes. If you are using business objects then
        also investigate System.Componen tModel.Bindingl ist(of T) as it's a real fast
        track to getting lists of your business classes bindable.
        >
        If you want multiple undo, the strategy is to deepcopy the underlying object
        with each edit and push it on a stack. System.Collecti ons.Generic.Sta ck(Of
        T) is great for this.
        >
        Represents a variable size last-in-first-out (LIFO) collection of instances of the same specified type.

        >
        Reverting to a precivious version is as simple as popping the object off the
        stack.
        >
        Chuck
        >
        >
        >
        "Cecco (ITA)" <CeccoITA@discu ssions.microsof t.comwrote in message
        news:17E2D1E8-85E4-40D5-B0DF-091B7A86241E@mi crosoft.com...
        (1) Why?
        Because I need to compare two forms with "equals" method.

        My intent is to determine, every time, if a user modified the form,
        althoug
        if he decided to change a data value and then undo the operation.

        If I stored data in a struct when the users undo the operation the
        begining
        struct and the newone will be equals.

        So, I think, but i'm not sure, if I can have a deep copy of a form at the
        begining with "equals" method I can know if someone has modified in some
        case
        the form, also if the datas remain the same.

        "Phill W." wrote:
        Cecco (ITA) wrote:
        >
        I need to know if there's a way to serialize a windows form.
        >
        (1) Why?
        Forms contain lots and /lots/ of data that you probably won't care about
        when serializing it.
        >
        I included the [serializable()]/<serializable in the "myclassfor m"
        declaration, but I
        declaration, but Ireceived an error because the windows.form class
        isn't marked
        as serializable.
        >
        And there's probably a Good Reason for that (see (1)).
        >
        What are you trying to /achieve/?
        If you want to save the Form's data then create a class to hold the data
        and teach that class how to save (and reload) itself.
        >
        Regards,
        Phill W.
        >
        >

        Comment

        Working...