我可以使用 savefiledialog 保存文件。保存文件后,如果我们对其进行编辑然后再次保存,则应在不打开 savefiledialog 的情况下保存它。请帮助我编写代码。
此代码是在 Windows 窗体中的 Visual Studio 2005 中制作的。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace win
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
StreamReader str = new StreamReader(openFileDialog1.FileName);
textBox1.Text = str.ReadToEnd();
str.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
{
StreamWriter wtr = new StreamWriter(saveFileDialog1.FileName);
wtr.Write(textBox1.Text);
wtr.Close();
}
}
}
}
}