{转载}c#Winform记录上次文本框/lable中的内容

C#WinForm文本框记忆上次输入文本内容

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

private void TestForm_Load(object sender, EventArgs e)
    {
        textBox1.Text = Properties.Settings.Default.diamLimit;
        textBox2.Text = Properties.Settings.Default.lenLimit;
    }
  • 1
  • 2
  • 3
  • 4
  • 5

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();
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

这样就可以记忆上次运行的内容了。

注意:需要添加引用:using **命名空间.Properties;

原文地址:https://www.cnblogs.com/ttplearning/p/14228869.html