So I am new to c# and WinForms and I am trying to save the contents of a textbox, all of the things I saw online were completely useless and to complete my project i need to be able to save the contents of a textbox between sessions.
Here is my code:
namespace Zero_Light_Fullstack
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string link1 = textBox1.Text;
Process.Start("chrome", @link1);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
}
}
Sorry is this is messy any answer is appreciated!
Does it need to be to a file?
You could create a string Setting in the application and save/access it when you like.
Accessing a setting.
textBox1.Text = Zero_Light_Fullstack.Properties.Settings.Default.LastText;
Updating a setting.
Zero_Light_Fullstack.Properties.Settings.Default.LastText = textBox1.Text;
Zero_Light_Fullstack.Properties.Settings.Default.Save();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.