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. Windows Forms
  4. How to save the Windows current view and reload when next time the application is started?

How to save the Windows current view and reload when next time the application is started?

Scheduled Pinned Locked Moved Windows Forms
windows-admindata-structurestutorialquestioncode-review
4 Posts 2 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.
  • S Offline
    S Offline
    Soma Shekhar
    wrote on last edited by
    #1

    Hi, I am writing code to reload the last active items and windows of the application, Basically I have 4 windows 2 are datagridview , 1. listview, 1 is tree view, in these 4 windows I can able add data from different files based on user selection. I need to reload all this when the application is restarted. currrently I am writing manually all data into the file and saved the file path location in windows registry, I felt it is very time consuming, and don't now how to improve the timimg, please provide your inputs is there a way to do this job in a simple manner. :)

    SomaShekhar

    R 1 Reply Last reply
    0
    • S Soma Shekhar

      Hi, I am writing code to reload the last active items and windows of the application, Basically I have 4 windows 2 are datagridview , 1. listview, 1 is tree view, in these 4 windows I can able add data from different files based on user selection. I need to reload all this when the application is restarted. currrently I am writing manually all data into the file and saved the file path location in windows registry, I felt it is very time consuming, and don't now how to improve the timimg, please provide your inputs is there a way to do this job in a simple manner. :)

      SomaShekhar

      R Offline
      R Offline
      Richard Blythe
      wrote on last edited by
      #2

      It sounds to me that you're on the right track. Saving state is really never easy. What I have done is created a UserPreference class for my apps. This is simply a class the encapsulates a the Dictionary<> object, which is new to .Net 2.0 What I do is init the dictionary like this: C#: Dictionary<string,> preference = new Dictionary<string,>; With the "preference" object, you can specify a unique string for the key and use it to store and retrieve as many items as necessary to restore the program state. This code model is not as messy but you will always have to do some "manual labor"! Cheers, Richard

      I've used up all my sick days, so today I'm calling in dead.

      S 1 Reply Last reply
      0
      • R Richard Blythe

        It sounds to me that you're on the right track. Saving state is really never easy. What I have done is created a UserPreference class for my apps. This is simply a class the encapsulates a the Dictionary<> object, which is new to .Net 2.0 What I do is init the dictionary like this: C#: Dictionary<string,> preference = new Dictionary<string,>; With the "preference" object, you can specify a unique string for the key and use it to store and retrieve as many items as necessary to restore the program state. This code model is not as messy but you will always have to do some "manual labor"! Cheers, Richard

        I've used up all my sick days, so today I'm calling in dead.

        S Offline
        S Offline
        Soma Shekhar
        wrote on last edited by
        #3

        Hi Richard, Thanks for your reply, I am not still clear, whether do I need to manually write all the forms information? if not could you please provide a code snippet how to avoid the manual updation. Thanks

        SomaShekhar

        R 1 Reply Last reply
        0
        • S Soma Shekhar

          Hi Richard, Thanks for your reply, I am not still clear, whether do I need to manually write all the forms information? if not could you please provide a code snippet how to avoid the manual updation. Thanks

          SomaShekhar

          R Offline
          R Offline
          Richard Blythe
          wrote on last edited by
          #4

          If there is any automatic save option, I don't know of it. Even if there was one provided by MS, it would generically store too much data and make the file size too large. For example, you don't want to be storing every attribute of the listView object: Font, BackColor, ForeColor, Items etc. Here's a generic example to illustrate the preference class: //Save the form's background color preferences.Add("windowsBColor", this.BackColor); -------- //Restore the windows backcolor if (preferences.ContainsKey("windowBColor")) { this.BackColor = (Color)(preferences["windowBColor"]); } If you need further assistance, don't hesitate to ask. Cheers! Richard

          My code this week has no errors. But it's Monday morning and I haven't got out of bed.

          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