c# 默认变量? Settings.Default,defaultCity=txtcity.text;怎么办?

发布于 2024-11-06 06:07:42 字数 636 浏览 1 评论 0原文

好吧,我下载了一个小麦程序,但现在不介意,我看着,比你写一个城市,你关闭程序,当你再次打开它时,它有你写的最后一个城市,怎么样?我看到它在whaterform_formClosed中有这个代码 但我如何创建这些变量?如果这是可能的,我可以在没有数据库的情况下编写程序吗?将所有内容保存在数据集中?或者数据表?默认数据库?默认数据集? 但现在我想知道如何创建默认变量

         private void weatherForm_FormClosed(object sender, FormClosedEventArgs e)
    {
        //Save Settings
        Settings.Default.defaultCity = txtCity.Text;
        Settings.Default.intervalText = comboBoxEdit1.Text;
        Settings.Default.windowPosition = this.Location;
        Settings.Default.timerOn = timer1.Enabled;
        Settings.Default.intervalTime = delay;
        Settings.Default.Save();
    }

Well i downloaded a program for wheater but it is not mind now, i watched, than you write a city and you close the program, and when you open it again, it has de last city you write, how is it? i watched it has this code in whaterform_formClosed
but how do i create these variables? and if this is posible can I to do a program without a database? saveing all in a dataset? or datatables? default databales? default dataset?
but now i want to know how to create a Default variable

         private void weatherForm_FormClosed(object sender, FormClosedEventArgs e)
    {
        //Save Settings
        Settings.Default.defaultCity = txtCity.Text;
        Settings.Default.intervalText = comboBoxEdit1.Text;
        Settings.Default.windowPosition = this.Location;
        Settings.Default.timerOn = timer1.Enabled;
        Settings.Default.intervalTime = delay;
        Settings.Default.Save();
    }

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

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

发布评论

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

评论(2

孤檠 2024-11-13 06:07:42

您可以使用“设置”来执行此操作:

从 .NET Framework 2.0 开始,
您可以创建并访问以下值
在应用程序之间保留
执行会话。这些值是
称为设置。设置即可
代表用户偏好,或
有价值的应用信息
需要使用。例如,您可能
创建一系列存储的设置
用户对配色方案的偏好
一个应用程序的。或者你可以存储
指定的连接字符串
您的应用程序使用的数据库。
设置允许你们都坚持
对以下事项至关重要的信息
代码之外的应用程序,以及
创建存储配置文件
个人用户的偏好。

有关详细信息,请参阅使用应用程序设置和用户设置

You can use 'settings' to do this:

Starting with the .NET Framework 2.0,
you can create and access values that
are persisted between application
execution sessions. These values are
called settings. Settings can
represent user preferences, or
valuable information the application
needs to use. For example, you might
create a series of settings that store
user preferences for the color scheme
of an application. Or you might store
the connection string that specifies a
database that your application uses.
Settings allow you to both persist
information that is critical to the
application outside the code, and to
create profiles that store the
preferences of individual users.

See Using Application Settings and User Settings for more information.

白色秋天 2024-11-13 06:07:42

存储此类信息的最简单方法是在配置文件中(就像在您的示例中一样)

如果您打开项目的属性,它会包含一个名为“设置”的选项卡。在其中添加您想要的属性,确保它们具有 User 范围,您应该能够执行非常类似的操作。

The easiest way to store information like this is in the config file (like it is in your example)

If you open the properties of your project, it contains a tab called settings. Add the properties that you want in there, make sure they have a scope of User and you should be able to do something very similar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文