Vb.net 保存/加载完整表单

Vb.net 保存/加载完整表单,vb.net,save,load,Vb.net,Save,Load,我在业余时间为一个朋友写一个程序,用来记录物理治疗和职业治疗的学生。我使用的是VisualBasic,到目前为止我已经创建了一个基本表单,但是我意识到我不知道如何保存/加载将要输入的信息 到目前为止,这就是表单的外观(基本我知道) 我目前无法访问sql或ms access,因此我希望能够将所有信息保存到txt文档或xml文件中,并能够在将来读取和更新它。最终,我将有多个表单,所有表单都与一个学生关联,并希望将它们一起保存 任何帮助都将不胜感激。您可以使用此方法,它可以完美地工作,但数据将存储在

我在业余时间为一个朋友写一个程序,用来记录物理治疗和职业治疗的学生。我使用的是VisualBasic,到目前为止我已经创建了一个基本表单,但是我意识到我不知道如何保存/加载将要输入的信息

到目前为止,这就是表单的外观(基本我知道)

我目前无法访问sql或ms access,因此我希望能够将所有信息保存到txt文档或xml文件中,并能够在将来读取和更新它。最终,我将有多个表单,所有表单都与一个学生关联,并希望将它们一起保存


任何帮助都将不胜感激。

您可以使用此方法,它可以完美地工作,但数据将存储在
xml
文件中,并且可以编辑:

首先进入项目属性:

Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
   My.Settings.StudentName = StudentNameTextBox.Text
   '.......
   '....
   'And you do that for all the information that you need to store.
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
     StudentNameTextBox.Text = My.Settings.StudentName
   '.......
   '....
   'And you do that for all the information that you need to load.
End Sub

然后进入设置选项卡:

Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
   My.Settings.StudentName = StudentNameTextBox.Text
   '.......
   '....
   'And you do that for all the information that you need to store.
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
     StudentNameTextBox.Text = My.Settings.StudentName
   '.......
   '....
   'And you do that for all the information that you need to load.
End Sub

然后添加所有需要存储数据的变量:

Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
   My.Settings.StudentName = StudentNameTextBox.Text
   '.......
   '....
   'And you do that for all the information that you need to store.
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
     StudentNameTextBox.Text = My.Settings.StudentName
   '.......
   '....
   'And you do that for all the information that you need to load.
End Sub

因此,要保存数据,您可以使用
表单关闭事件:

Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
   My.Settings.StudentName = StudentNameTextBox.Text
   '.......
   '....
   'And you do that for all the information that you need to store.
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
     StudentNameTextBox.Text = My.Settings.StudentName
   '.......
   '....
   'And you do that for all the information that you need to load.
End Sub
要在加载表单时加载数据,只需反转存储方式:

Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
   My.Settings.StudentName = StudentNameTextBox.Text
   '.......
   '....
   'And you do that for all the information that you need to store.
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
     StudentNameTextBox.Text = My.Settings.StudentName
   '.......
   '....
   'And you do that for all the information that you need to load.
End Sub

希望这对您有用:)

您可以使用此方法,它可以完美地工作,但数据将存储在
xml
文件中,并且是可编辑的:

首先进入项目属性:

Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
   My.Settings.StudentName = StudentNameTextBox.Text
   '.......
   '....
   'And you do that for all the information that you need to store.
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
     StudentNameTextBox.Text = My.Settings.StudentName
   '.......
   '....
   'And you do that for all the information that you need to load.
End Sub

然后进入设置选项卡:

Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
   My.Settings.StudentName = StudentNameTextBox.Text
   '.......
   '....
   'And you do that for all the information that you need to store.
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
     StudentNameTextBox.Text = My.Settings.StudentName
   '.......
   '....
   'And you do that for all the information that you need to load.
End Sub

然后添加所有需要存储数据的变量:

Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
   My.Settings.StudentName = StudentNameTextBox.Text
   '.......
   '....
   'And you do that for all the information that you need to store.
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
     StudentNameTextBox.Text = My.Settings.StudentName
   '.......
   '....
   'And you do that for all the information that you need to load.
End Sub

因此,要保存数据,您可以使用
表单关闭事件:

Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
   My.Settings.StudentName = StudentNameTextBox.Text
   '.......
   '....
   'And you do that for all the information that you need to store.
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
     StudentNameTextBox.Text = My.Settings.StudentName
   '.......
   '....
   'And you do that for all the information that you need to load.
End Sub
要在加载表单时加载数据,只需反转存储方式:

Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
   My.Settings.StudentName = StudentNameTextBox.Text
   '.......
   '....
   'And you do that for all the information that you need to store.
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
     StudentNameTextBox.Text = My.Settings.StudentName
   '.......
   '....
   'And you do that for all the information that you need to load.
End Sub

希望这将对您有用:)

请阅读并采取行动。根据数据在应用程序中的存储方式,序列化可能是一个选项或SQLite。很难说,有这么宽泛和模糊的东西,请阅读并采取行动。根据数据在应用程序中的存储方式,序列化可能是一个选项或SQLite。很难说这么宽泛和模糊,太棒了!非常感谢。@willeclerc,不客气:),如果答案对你有用,请接受它,这样它也可以帮助别人。太棒了!非常感谢。@willeclerc,不客气:),如果答案对你有用,请接受它,这样它也可以帮助别人。