Сложности с вставкой кода - C#
Формулировка задачи:
Привет я написал код и удалил нечайно и теперь не могу понять где и как он стоял суть в том что он должен копировать введеные данные с текстбоксов и сохронять в тхт файл, подскажите как правильно и куда его разместить вот код:
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
public static bool Exists()
{
if (File.Exists("Настройки.txt")) File.Delete("Настройки.txt");
FileStream file = new FileStream("Настройки.txt", FileMode.Create);
StreamWriter fnew = new StreamWriter(file, Encoding.GetEncoding(1251));
fnew.WriteLine(textBox1.Text);
fnew.WriteLine(textBox2.Text);
fnew.WriteLine(textBox3.Text);
fnew.WriteLine(textBox4.Text);
fnew.Close();
Close();
return true;
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
}
}
}Решение задачи: «Сложности с вставкой кода»
textual
Листинг программы
using System;
using System.IO;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void Exists()
{
if (File.Exists("Настройки.txt")) File.Delete("Настройки.txt");
FileStream file = new FileStream("Настройки.txt", FileMode.Create);
StreamWriter fnew = new StreamWriter(file, Encoding.GetEncoding(1251));
fnew.WriteLine(textBox1.Text);
fnew.WriteLine(textBox2.Text);
fnew.WriteLine(textBox3.Text);
fnew.WriteLine(textBox4.Text);
fnew.Close();
}
private void button1_Click(object sender, EventArgs e)
{
Exists();
}
}
}