Вот код:
Код: Выделить всё
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1(){
InitializeComponent();
}
private void apri_file_Click(object sender, EventArgs e){
if (openFileDialog1.ShowDialog() == DialogResult.OK){
System.IO.StreamReader input = new
System.IO.StreamReader(openFileDialog1.FileName);
TextBox_stampa_contenuto.Text = System.IO.File.ReadAllText(openFileDialog1.FileName);
input.Close();
}
}
private void salva_file_Click(object sender, EventArgs e){
DialogResult result = saveFileDialog1.ShowDialog();
if (result == DialogResult.OK){
string name = saveFileDialog1.FileName;
File.WriteAllText(name, TextBox_stampa_contenuto.Text);
}
}
private void nuovo_file_Click(object sender, EventArgs e)
{
if (TextBox_stampa_contenuto.Text.Trim().Length != 0)
{
Form2 Salva = new Form2();
Salva.Show();
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void salva_Click(object sender, EventArgs e)
{
DialogResult result = saveFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
string name = saveFileDialog1.FileName;
File.WriteAllText(name, TextBox_stampa_contenuto.Text);
}
}
private void non_salvare_Click(object sender, EventArgs e)
{
TextBox_stampa_contenuto.Clear();
}
private void annulla_Click(object sender, EventArgs e)
{
}
}
}
Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/216 ... ms-c-sharp