//主窗体部分
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;
using System.Drawing.Printing;
namespace notepad
{
public partial class Form1 : Form
{
public string path="";
public string wenben;
public bool saved;
System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
public Form1()
{
InitializeComponent();
// richTextBox1.Size.Width = this.Size.Width;
// richTextBox1.Size.Height = this.Size.Height;
saved = false ;
this.Paint+=new PaintEventHandler(Form1_Paint);
this.FormClosing+=new FormClosingEventHandler(Form1_FormClosing);
//richTextBox1.b;
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
wenben = richTextBox1.Text;
}
private void Form1_Load(object sender, EventArgs e)
{
this.toolStripStatusLabel1.Text = "当前时间为 "+DateTime.Now.ToShortTimeString();
this.toolStripStatusLabel2.Text= "20082121003 鲍东升制作";
this.toolStripStatusLabel3.Text = " 软件综合课程设计";
printPreviewControl1.Document = pd;
}
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "*.txt(文本文档)|*.txt";
if(openFileDialog1.ShowDialog()==DialogResult.OK)
{
StreamReader SReader=new StreamReader(openFileDialog1.FileName,Encoding.Default);
richTextBox1.Text = SReader.ReadToEnd();
// richTextBox1.Font = SReader.;
SReader.Close();
path = openFileDialog1.FileName;
}
this.Text = openFileDialog1.SafeFileName;
// richTextBox1.LoadFile(path);
// MessageBox.Show(path);
}
private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e)
{
saveFileDialog1.Filter = "*.txt(文本文档)|*.txt";
if(saveFileDialog1.ShowDialog()==DialogResult.OK)
{
StreamWriter SWriter = new StreamWriter(saveFileDialog1.FileName, true);
SWriter.Write(richTextBox1.Text);
SWriter.Close();
}
saved = true;
}
private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
{
saveFileDialog1.DefaultExt = "*.txt";
// RichTextBoxStreamType = "*.txt";
if (path.Length > 0)
{
richTextBox1.SaveFile(path, RichTextBoxStreamType.TextTextOleObjs);
// MessageBox.Show(path);
}
else
{
saveFileDialog1.Filter = "*.txt(文本文档)|*.txt"