应用程序执行之间preserve数据 [英] Preserve data between application executions

查看:251
本文介绍了应用程序执行之间preserve数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些文本框的应用程序。我的用户填写文本框和运行一些方法中,当它们关闭应用程序数据丢失(通常)。

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).

我想保留一对夫妇文本框和一些局部变量的值。这是不值得使用数据库,和简单的 .TXT 文件是不够干净,有没有其他的简单,存储的数据量小应用程序运行之间的简单方法是什么?

I want to keep the value of a couple of textboxes and some local variables. It's not worth it to use database, and simple .txt files are not clean enough, is there any other simple and brief way of storing little volumes of data between application runs?

我不知道,但听说过的资源文件的一些缕缕,都有益于这种情况?

I'm not sure but have heard some wisps about resource files, are they good for this case?

推荐答案

简单的方法是结合你的文本框来应用程序设置

Simplest way is binding your textboxes to application settings:

  • 选择texbox要preserve
  • 转到属性>数据>(的applicationSettings)
  • 添加应用程序设置绑定到Text属性
  • FormClosed 事件保存应用程序设置
  • select texbox you want to preserve
  • go to Properties > Data > (ApplicationSettings)
  • add application settings binding to Text property
  • on FormClosed event save application 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:

  • 开启属性下的项目文件夹> Settings.settings
  • 要存储
  • 添加设置(如MyCounter)
  • 设置MyCounter类型,范围和默认值(例如int,用户,0)
  • 阅读设置到本地变量变种X = Settings.Default.MyCounter
  • 在形成封闭保存设置 Settings.Default.MyCounter = X 之前调用 Settings.Default.Save()
  • 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()

这篇关于应用程序执行之间preserve数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆