保存 Textbox 中的数据并保留在下一个会话中 [英] Save data from Textbox and persist in the next session
问题描述
我想从 TextBox
保存一些数据.此信息由用户输入.
I would like to save some data from a TextBox
. This information is entered by a user.
在我的 Form_Load
事件处理程序中,我设置了 Button1.Enabled = False
并让用户输入 right_serial_code
到 TextBox1
.如果代码正确,则启用Button1
.
In my Form_Load
event handler I set Button1.Enabled = False
and have user input right_serial_code
into TextBox1
. If the code is correct, Button1
is enabled.
如果用户输入正确的序列号,它应该在下一个会话中持久化.以便下次程序启动时,用户无需重新输入.
If users puts the correct serial code, it should be persisted in the next session. So that next time the program starts, user does not need to re-enter.
推荐答案
转到您的项目属性页面并打开设置"选项卡.创建一个名为 SerialCode
的新设置.将 Type
设置为 String
并将 Scope
设置为 User
(因此每个操作系统用户都保存自己的序列号) 或 Application
(因此机器上的所有用户共享相同的序列号).
Go to your project properties page and open the "Settings" tab. Create a new setting called SerialCode
. Set the Type
to String
and set the Scope
to either User
(so each OS user saves their own serial code) or Application
(so all users on the machine share the same serial code).
然后,在 Form_Load
事件处理程序中,执行如下操作:
Then, in the Form_Load
event handler, do something like this:
TextBox1.Text = My.Settings.SerialCode
然后在 Button1_Click
事件处理程序中,像这样:
And then in the Button1_Click
event handler, so something like this:
My.Settings.SerialCode = TextBox1.Text
这篇关于保存 Textbox 中的数据并保留在下一个会话中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!