Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Saving the current state of a form

Saving the current state of a form

Scheduled Pinned Locked Moved C#
xmljsonhelpquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 3 Offline
    3 Offline
    3Dizard
    wrote on last edited by
    #1

    Well, as the title says I want to save the current state of a Windows.Form object. I'm currently investigating on doing this with xml-serialization, but I don't know if this is the way to go. I don't need a complete essay about that (I would take that, too) but a hint that points me into the right direction. So, can someone help me out please? Greetings

    J B R 3 Replies Last reply
    0
    • 3 3Dizard

      Well, as the title says I want to save the current state of a Windows.Form object. I'm currently investigating on doing this with xml-serialization, but I don't know if this is the way to go. I don't need a complete essay about that (I would take that, too) but a hint that points me into the right direction. So, can someone help me out please? Greetings

      J Offline
      J Offline
      Josh Smith
      wrote on last edited by
      #2

      You won't be able to serialize a Form object. It's not serializable. What you can do is serialize the state of the application's data, and then reload that instead. XML serialization should work fine for that, but you might as well use the BinaryFormatter because it's faster and more compact. If you also want to save the state of individual controls on a form, then you better hope that you're using some good 3rd party controls, like Infragistics. The MS inbox controls suck, and as such, don't provide runtime serialization APIs. But some 3rd party controls will save user configured settings for you, which is a nice feature for most apps. Josh

      1 Reply Last reply
      0
      • 3 3Dizard

        Well, as the title says I want to save the current state of a Windows.Form object. I'm currently investigating on doing this with xml-serialization, but I don't know if this is the way to go. I don't need a complete essay about that (I would take that, too) but a hint that points me into the right direction. So, can someone help me out please? Greetings

        B Offline
        B Offline
        BoneSoft
        wrote on last edited by
        #3

        Binary formatter will not work if the class changes. Meaning if you try to read a config file that was written before changes were made to the class. Xml serialization is a safer way to go. Just create a simple class that hold the information you require and make it XML serializable. Use my article[^] if you need help with the serialization.


        Try code model generation tools at BoneSoft.com.

        3 1 Reply Last reply
        0
        • 3 3Dizard

          Well, as the title says I want to save the current state of a Windows.Form object. I'm currently investigating on doing this with xml-serialization, but I don't know if this is the way to go. I don't need a complete essay about that (I would take that, too) but a hint that points me into the right direction. So, can someone help me out please? Greetings

          R Offline
          R Offline
          Rojan Gh
          wrote on last edited by
          #4

          Hi! In C# v2.0 (Visual Studio 2005), there is a file, named Settings.settings in the properties folder in the Solution Explorer window, there you can assign some settings in different types and so you can assign a property like this: Name: FormPosition Type: System.Drawing.Point Scope: User (Take care of this, it made me crazy to get this point: Application scope, is read-only and it will be the same as the value you gave to it at the beginning and you can not change it at runtime! But User scope is made to be assigned both at the beginning and at runtime. :cool:) Value: 100, 100 and then at runtime, you can access this settings by using this code: Point formPosition = global::YourNamespace.Properties.Settings.Default.FormPosition;//YourNamespace = (The main namespace of your application) and even you can change the value at runtime this way: Point formPosition = new Point(MyForm.Left, MyForm.Top); global::YourNamespace.Properties.Settings.Default.FormPosition = formPosition;//YourNamespace = (The main namespace of your application) These values will be automatically stored in the registry of windows, and in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\RNG and in binary mode that is coded and not recoverable by users, but by your application.:laugh: Hope you could use it!:rose: Sojaner!

          1 Reply Last reply
          0
          • B BoneSoft

            Binary formatter will not work if the class changes. Meaning if you try to read a config file that was written before changes were made to the class. Xml serialization is a safer way to go. Just create a simple class that hold the information you require and make it XML serializable. Use my article[^] if you need help with the serialization.


            Try code model generation tools at BoneSoft.com.

            3 Offline
            3 Offline
            3Dizard
            wrote on last edited by
            #5

            If I got that right: Due to containing interfaces many classes can't be serialized. I want to save the state of my windows form. So I need to serialize elements of this form. These are Controls (Labels and UserControls). If the above applies, I see no way doing so, except serializing lets say the Text of a Label and then later deserialize the string, create a new Label and set the Text to the deserialized string, which is a really bad situation. Is there any better way?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups