using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 进程和线程
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
panel1.Visible = false; //隐藏listbox,即历史记录
}
String[] path;
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "请选择文本文件";
ofd.Multiselect = true;
ofd.Filter = "文本文件|*.txt";
ofd.ShowDialog();
path = ofd.FileNames;
if (path.Length <= 0)
{
return;
}
for (int i = 0; i < path.Length; i++)
{
listBox1.Items.Add(Path.GetFileName(path[i]));
}
ShowContent(0);
}
private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "请选择保存的文件夹";
sfd.InitialDirectory = @"c:\";
sfd.Filter = "文本文件|*.txt";
sfd.ShowDialog();
String fileName = sfd.FileName;
if(fileName == "")
{
return;
}
using (FileStream fwrite = new FileStream(fileName, FileMode.OpenOrCreate))
{
byte[] buf = new byte[1024 * 1024 * 5];
buf = Encoding.UTF8.GetBytes(textBox1.Text);
fwrite.Write(buf, 0, buf.Length);
}
}
private void 自动换行ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!textBox1.WordWrap)
{
textBox1.WordWrap = true;
自动换行ToolStripMenuItem.Text = "取消自动换行";
}
else
{
自动换行ToolStripMenuItem.Text = "取消自动换行";
}
}
private void 字体ToolStripMenuItem_Click(object sender, EventArgs e)
{
FontDialog fd = new FontDialog();
fd.ShowDialog();
textBox1.Font = fd.Font;
}
private void 颜色ToolStripMenuItem_Click(object sender, EventArgs e)
{
ColorDialog cd = new ColorDialog();
cd.ShowDialog();
textBox1.ForeColor = cd.Color;
}
private void 显示ToolStripMenuItem_Click(object sender, EventArgs e)
{
panel1.Visible = true;
}
private void 隐藏ToolStripMenuItem_Click(object sender, EventArgs e)
{
panel1.Visible = false;
}
private void button1_Click(object sender, EventArgs e)
{
panel1.Visible = false;
}
private void listBox1_DoubleClick(object sender, EventArgs e)
{
ShowContent(listBox1.SelectedIndex);
}
private void ShowContent(int p)
{
using (FileStream fread = new FileStream(path[p], FileMode.Open))
{
byte[] buf = new byte[1024 * 1024 * 5];
fread.Read(buf, 0, buf.Length);
textBox1.Text = System.Text.Encoding.UTF8.GetString(buf);
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 进程和线程
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
panel1.Visible = false; //隐藏listbox,即历史记录
}
String[] path;
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "请选择文本文件";
ofd.Multiselect = true;
ofd.Filter = "文本文件|*.txt";
ofd.ShowDialog();
path = ofd.FileNames;
if (path.Length <= 0)
{
return;
}
for (int i = 0; i < path.Length; i++)
{
listBox1.Items.Add(Path.GetFileName(path[i]));
}
ShowContent(0);
}
private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "请选择保存的文件夹";
sfd.InitialDirectory = @"c:\";
sfd.Filter = "文本文件|*.txt";
sfd.ShowDialog();
String fileName = sfd.FileName;
if(fileName == "")
{
return;
}
using (FileStream fwrite = new FileStream(fileName, FileMode.OpenOrCreate))
{
byte[] buf = new byte[1024 * 1024 * 5];
buf = Encoding.UTF8.GetBytes(textBox1.Text);
fwrite.Write(buf, 0, buf.Length);
}
}
private void 自动换行ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!textBox1.WordWrap)
{
textBox1.WordWrap = true;
自动换行ToolStripMenuItem.Text = "取消自动换行";
}
else
{
自动换行ToolStripMenuItem.Text = "取消自动换行";
}
}
private void 字体ToolStripMenuItem_Click(object sender, EventArgs e)
{
FontDialog fd = new FontDialog();
fd.ShowDialog();
textBox1.Font = fd.Font;
}
private void 颜色ToolStripMenuItem_Click(object sender, EventArgs e)
{
ColorDialog cd = new ColorDialog();
cd.ShowDialog();
textBox1.ForeColor = cd.Color;
}
private void 显示ToolStripMenuItem_Click(object sender, EventArgs e)
{
panel1.Visible = true;
}
private void 隐藏ToolStripMenuItem_Click(object sender, EventArgs e)
{
panel1.Visible = false;
}
private void button1_Click(object sender, EventArgs e)
{
panel1.Visible = false;
}
private void listBox1_DoubleClick(object sender, EventArgs e)
{
ShowContent(listBox1.SelectedIndex);
}
private void ShowContent(int p)
{
using (FileStream fread = new FileStream(path[p], FileMode.Open))
{
byte[] buf = new byte[1024 * 1024 * 5];
fread.Read(buf, 0, buf.Length);
textBox1.Text = System.Text.Encoding.UTF8.GetString(buf);
}
}
}
}