我想创建一个程序,让我在其中打开一个txt文件,然后允许我编辑然后保存它。我正在尝试将文件目录设置为selectedFile变量。
我的代码:
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 TabControl
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string selectedFile;
FileStream file = new FileStream(SELECTEDFILE, fileMode.Open, FileAccess.Write);
private void button1_Click(object sender, EventArgs e)
{
btnBack.Visible = true;
tabControl1.SelectedIndex = 1;
btnSave.BringToFront();
}
private void button2_Click(object sender, EventArgs e)
{
btnBack.Visible = false;
tabControl1.SelectedIndex = 0;
btnSave.SendToBack();
}
private void button3_Click(object sender, EventArgs e)
{
Close();
}
private void btnBrowse_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
txtDirectory.Text = openFileDialog1.FileName;
selectedFile = openFileDialog1.FileName;
}
}
}
我正在尝试使用selectedFile作为文件流的目录,但是我尝试过的方法不起作用,我将如何完成此操作?