vb.net 如何保存在VB中所做的设置?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17351800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 14:04:15  来源:igfitidea点击:

How to save settings made in VB?

vb.netvisual-studio-2008

提问by Dani Mateo

Is there any way I can save changes made by a user , so that at the next run they would still be there? I have seen something about My.Settings , is that how it is done?

有什么方法可以保存用户所做的更改,以便在下次运行时它们仍然存在?我已经看到了一些关于 My.Settings 的东西,它是如何完成的?

回答by Mark Hall

Yes you have multiple options, you can create a file and load it on startup, or you can use the built in settings object. Just go to your Project Property's--> settingsset your variable there, the you can access it through My.Settings

是的,您有多种选择,您可以创建一个文件并在启动时加载它,或者您可以使用内置的设置对象。只需转到您的Project Property's-->settings在那里设置您的变量,您就可以通过它访问它My.Settings

enter image description here

在此处输入图片说明

Then load it like this:

然后像这样加载它:

Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    Dim greeting As String = My.Settings.mySetting
End Sub

you would change the value and save it like this

你会改变这个值并像这样保存它

My.Settings.mySetting = "GoodBye"
My.Settings.Save()