使TextBox能够记住上一次的输入文本,简单设置即可实现,简单好用:
1)项目 右键–> 属性–>设置 --> 添加名称及对应的值

2)为TextBox赋值
private void TestForm_Load(object sender, EventArgs e)
{
textBox1.Text = Properties.Settings.Default.diamLimit;
textBox2.Text = Properties.Settings.Default.lenLimit;
}
3)记忆TextBox中输入的值
首先:为Form窗体添加事件FormClose
private void TestForm_FormClose(object sender, FormClosedEventArgs e)
{
Properties.Settings.Default.diamLimit = textBox1.Text;
Properties.Settings.Default.lenLimit = textBox2.Text;
Properties.Settings.Default.Save();
}
这样就可以记忆上次运行的内容了。
注意:需要添加引用:using **命名空间.Properties;
本文介绍了一种在C#中使TextBox控件记住上次输入文本的方法。通过在Form窗体的加载和关闭事件中调用Properties.Settings.Default,可以轻松实现TextBox内容的记忆功能,确保下次程序启动时能显示上一次的输入内容。
1114

被折叠的 条评论
为什么被折叠?



