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;
using System.Diagnostics;
namespace text
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Text = "";
}
private void endToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
String text = richTextBox1.Text;
textToFile(saveFileDialog1.FileName, text);
}
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
String text = fileToText(openFileDialog1.FileName);
richTextBox1.Text = text;
}
}
public static String fileToText(String filePath)
{
StreamReader file = new StreamReader(filePath);
String text = file.ReadToEnd();
file.Close();
return text;
}
public static void textToFile(String filePath, String text)
{
StreamWriter file = new StreamWriter(filePath);
file.Write(text);
file.Close();
}
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
String text = richTextBox1.Text;
textToFile(saveFileDialog1.FileName, text);
}
}
private void aboutTextToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("基本的文字編輯器,可用以建立簡單的文件。\n作者:李錫昱\n2011 年 12 月 6 日");
}
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("按下file後,有五個功能:\n1.new 開啟一個新的檔案 \n2.open 開啟一個原有的的檔案\n3.save 儲存現在所在使用的檔案\n4.save as 重新命名再儲存一次檔案\n5.end 結束");
}
}
}





