Preserve data between application executions

后端 未结 4 1385
长发绾君心
长发绾君心 2020-12-01 17:03

I have an application with some textboxes. My user fills the textboxes and runs some methods, when they close the application data is lost (normally).

I want to ke

相关标签:
4条回答
  • 2020-12-01 17:20

    There are a couple of options, but with most of them, you're going to be putting a file somewhere, whether it's a text file, resources/config or binary.

    Using settings is one option: http://www.codeproject.com/Articles/17659/How-To-Use-the-Settings-Class-in-C

    You can also take the serialization route: http://msdn.microsoft.com/en-us/library/vstudio/et91as27.aspx

    Or you could possibly look into noSQL databases like MongoDB: http://www.mongodb.org/

    0 讨论(0)
  • 2020-12-01 17:21

    Simplest way is binding your textboxes to application settings:

    • select texbox you want to preserve
    • go to Properties > Data > (ApplicationSettings)
    • add application settings binding to Text property
    • on FormClosed event save application settings

    Saving settings:

    private void Form_FormClosed(object sender, FormClosedEventArgs e)
    {
        Settings.Default.Save();
    }
    

    Next time when user will start your application, settings will be loaded from user-specific file, and textboxes will be filled with same data as it was before user closed an application last time.

    Also in application settings you can store local variables, but you will have to add settings for them manually, and manually read that setting on application start:

    • open Properties folder under project > Settings.settings
    • add settings you want to store (e.g. MyCounter)
    • set MyCounter type, scope, and default value (e.g. int, User, 0)
    • read setting to your local variable var x = Settings.Default.MyCounter
    • on form closed save setting Settings.Default.MyCounter = x just before calling Settings.Default.Save()
    0 讨论(0)
  • 2020-12-01 17:34

    You may use following

    1- A local MS-ACCESS based db which can store small footprint.

    2- Use Dictionary , Serilize/Deserilize it on hard disk (Uses FileSystem)

    3- Store it in windows registry

    0 讨论(0)
  • 2020-12-01 17:44

    Assuming you're on Windows (as the tags imply), have you considered the registry?

    0 讨论(0)
提交回复
热议问题