在VB.NET中保存关闭/重启PC上的数据

时间:2014-09-02 12:59:37

标签: vb.net settings

如何从文本框中保存数据,以便在重新启动时,计算机数据仍然存在?

我通过使用:数据库和设置来了解该方法。我通过设置添加了它,但是当我重新启动电脑时,数据消失了。

代码:

Private Sub form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
    My.Settings.txt1 = TextBox1.Text
    My.Settings.txt2 = TextBox2.Text

End Sub


Private Sub form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    TextBox1.Text = My.Settings.txt1
    TextBox2.Text = My.Settings.txt2
End Sub

1 个答案:

答案 0 :(得分:0)

Private Sub form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
My.Settings.txt1 = TextBox1.Text
My.Settings.txt2 = TextBox2.Text
My.Settings.Save()
End Sub


Private Sub form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    TextBox1.Text = My.Settings.txt1
    TextBox2.Text = My.Settings.txt2
End Sub