如何在 C# 中保存设置

发布于 2024-10-10 05:16:07 字数 69 浏览 0 评论 0原文

我正在构建一个独立的程序,因此没有外部文件可供程序访问。回忆上次关闭之前窗口的大小以及窗口内某个元素的位置的最佳方法是什么?

I am building a stand alone program so there are no external files for the program to access. What would be the best way to recall what the size of the window, and the location of a certain element inside the window were prior the the last shut down?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

傻比既视感 2024-10-17 05:16:08

我会使用 .NET 提供的设置来完成此操作,这非常舒适:
http://msdn.microsoft.com/en -us/library/aa730869%28v=vs.80%29.aspx

I would do it with Settings provided by .NET, that's quiet comfortable:
http://msdn.microsoft.com/en-us/library/aa730869%28v=vs.80%29.aspx

情归归情 2024-10-17 05:16:08

好吧,我认为选项有两个:

  • 此外,如果您不使用外部文件,您可以将设置存储在自动生成的 .config 文件中;
  • 将值保存在注册表中;

对于第一个选项,请查看MSDN,对于第二个选项,请尝试查看< a href="http://msdn.microsoft.com/en-us/library/2kzb96fk.aspx" rel="nofollow">此处。

编辑:如何写入注册表:

RegistryKey currentUser = Registry.CurrentUser;
RegistryKey subKey = currentUser.CreateSubKey("MyTest", RegistryKeyPermissionCheck.ReadWriteSubTree);
subKey.SetValue("WindowHeight", 1024);
subKey.SetValue("WindowWidth", 1024);

Well, I think the options are two:

  • Also if you're not using external files you could store your settings in the auto-generated .config file;
  • Save the values in the registry;

For the first option look at MSDN, for the second try to look here.

EDIT: How to write into the registry:

RegistryKey currentUser = Registry.CurrentUser;
RegistryKey subKey = currentUser.CreateSubKey("MyTest", RegistryKeyPermissionCheck.ReadWriteSubTree);
subKey.SetValue("WindowHeight", 1024);
subKey.SetValue("WindowWidth", 1024);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文