private void SaveListBox() { int index = this.listBox1.SelectedIndex; DialogResult result = MessageBox.Show("是否保留当前修改", "警告", MessageBoxButtons.OKCancel); if (result == DialogResult.OK) { string text = this.textBox1.Text; MessageBox.Show(text); FileStreamUtil filestream = new FileStreamUtil(); filestream.WriterFile(filenames[index], text); } this.textBox1.Clear(); this.listBox1.Items.RemoveAt(index); filenames.RemoveAt(index); }
private void 打开ToolStripMenuItem1_Click(object sender, EventArgs e) { this.openFileDialog1.FileName = Environment.CurrentDirectory; if (this.listBox1.Items.Count >= 2) { SaveListBox(); } this.openFileDialog1.ShowDialog(); string filename = this.openFileDialog1.FileName; filenames.Add(filename); FileStreamUtil filestream = new FileStreamUtil(); List <string> list = filestream.ReaderFile(filename); foreach (string str in list) { this.textBox1.Text += str; } this.listBox1.Items.Add(Path.GetFileName(filename)); }
private void 新建ToolStripMenuItem1_Click(object sender, EventArgs e) { saveFileDialog1.FileName = "测试"; saveFileDialog1.DefaultExt = ".txt"; saveFileDialog1.Filter = "文本文件|*.txt"; saveFileDialog1.Title = "浏览文本文件"; saveFileDialog1.InitialDirectory = @"C:\"; saveFileDialog1.RestoreDirectory = true; DialogResult result = this.saveFileDialog1.ShowDialog(); if (result != DialogResult.OK) { return; } string path = saveFileDialog1.FileName.ToString(); FileStreamUtil stream = new FileStreamUtil(); stream.CreateFile(path); filenames.Add(path); string filename = Path.GetFileName(saveFileDialog1.FileName); listBox1.Items.Add(filename); }