Reputation: 636
I am working on a project where I want to save the text that is in the textbox when im closing the application, and when I open the application again I want it to be there.
I am trying to save the text data in the app.config as you can see in the code below but when I close the application and run it, the text I put in is not there.
Im really confused because when the form loads it runs this
textbox1.Text = Properties.Settings.Default.SavedText;
and it should pull up the "saved text" which is being saved when the form is calling the Closing event
Properties.Settings.Default.SavedText = textbox1.Text;
Properties.Settings.Default.Save();
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MetroFramework;
using MetroFramework.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : MetroForm
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
textbox1.Text = Properties.Settings.Default.SavedText;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Properties.Settings.Default.SavedText = textbox1.Text;
Properties.Settings.Default.Save();
}
}
}
I was also getting these errors before and I tried showing the potential fixes and use them but they didnt solve the issue with the text not saving.
This were the potential fixes.
Upvotes: 1
Views: 598
Reputation: 636
I solved the issue by going into my project properties and adding this to the project settings. SavedText > String > User.
Upvotes: 1