c# 默认变量? Settings.Default,defaultCity=txtcity.text;怎么办?
好吧,我下载了一个小麦程序,但现在不介意,我看着,比你写一个城市,你关闭程序,当你再次打开它时,它有你写的最后一个城市,怎么样?我看到它在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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用“设置”来执行此操作:
有关详细信息,请参阅使用应用程序设置和用户设置。
You can use 'settings' to do this:
See Using Application Settings and User Settings for more information.
存储此类信息的最简单方法是在配置文件中(就像在您的示例中一样)
如果您打开项目的属性,它会包含一个名为“设置”的选项卡。在其中添加您想要的属性,确保它们具有 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.