public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
panel1.Visible = true;
}
private void button2_Click(object sender, EventArgs e)
{
panel1.Visible = false;
}
private void Form1_Load(object sender, EventArgs e)
{
panel1.Visible = false;
// 取消自动换行
textBox1.WordWrap = false;
}
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_1(object sender, EventArgs e)
{
panel1.Visible = true;
}
List<string > lis=new List<string>();
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog op = new OpenFileDialog();
op.Title = "选择你要打开的文件";
op.InitialDirectory = @"C:\Users\Administrator\Desktop";
op.Filter = "文本文件|*.txt";
op.Multiselect = true;
op.ShowDialog();
string na = op.FileName; //获得文件的路径
lis.Add (na);
//获得文件名
string path = Path.GetFileName(na);
listBox1.Items.Add(path);
if (na == "")
{
return;
}
using (FileStream rdfile = new FileStream(na, FileMode.OpenOrCreate, FileAccess.Read))
{
byte[] by = new byte[1024];
int name = rdfile.Read(by, 0, by.Length);
string str1 = Encoding.Default.GetString(by, 0, name);
textBox1.Text = str1;
}
}
private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog sav = new SaveFileDialog();
sav.Title = "保存到指定的文件夹中";
sav.Filter = "所有的文件|*.*";
sav.ShowDialog();
string ps = sav.FileName; // 获得用户要保存的文件路径
if (ps == "")
return;
using (FileStream fs = new FileStream(ps, FileMode.OpenOrCreate, FileAccess.Write))
{
string str2 = textBox1.Text;
byte[] bb = Encoding.Default.GetBytes(str2);
fs.Write(bb, 0, bb.Length);
}
MessageBox.Show("保存成功");
}
private void 自动换行ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (自动换行ToolStripMenuItem.Text == "自动换行")
{
textBox1.WordWrap = true;
自动换行ToolStripMenuItem.Text = "取消自动换行";
}
else
{
textBox1.WordWrap = false;
自动换行ToolStripMenuItem.Text = "自动换行";
}
}
private void 字体ToolStripMenuItem_Click(object sender, EventArgs e)
{
FontDialog fon = new FontDialog();
fon.ShowDialog();
textBox1.Font = fon.Font;
}
private void 颜色ToolStripMenuItem_Click(object sender, EventArgs e)
{
ColorDialog col = new ColorDialog();
col.ShowDialog();
textBox1.ForeColor = col.Color; // 选中的颜色进行复制
}
private void listBox1_DoubleClick(object sender, EventArgs e)
{
string paa=lis[listBox1 .SelectedIndex ];
if(paa=="")
return ;
using (FileStream rdfile = new FileStream(paa, FileMode.OpenOrCreate, FileAccess.Read))
{
byte[] by = new byte[1024];
int name = rdfile.Read(by, 0, by.Length);
string str1 = Encoding.Default.GetString(by, 0, name);
textBox1.Text = str1;
}
}
}
}