多文档文本编辑器代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
多文档文本编辑器代码
using System;
using System.Collections.Generic;
using ponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
private string currentfilename;
public string mainkey = null;
public bool MaxOrMin;
//处理文件名子程序
private void setcurrentfilename(string filepath)
{
currentfilename = filepath;
this.Text = Path.GetFileName(currentfilename) + " -记事本"; }
//窗口初始化程序
public Form1()
{
InitializeComponent();
撤销UToolStripMenuItem.Enabled = false;
复制CToolStripMenuItem.Enabled = false;
剪切TToolStripMenuItem.Enabled = false;
删除LToolStripMenuItem.Enabled = false;
if (Clipboard.ContainsText() == true)
{
粘帖PToolStripMenuItem.Enabled = true;
}
else
{
粘帖PToolStripMenuItem.Enabled = false;
}
}
{
textBox1.Text = "";
setcurrentfilename("无标题");
}
private void打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
setcurrentfilename(openFileDialog1.FileName);
textBox1.Text=File.ReadAllText(currentfilename);
}
}
private void保存SToolStripMenuItem_Click(object sender, EventArgs e)
{
if (currentfilename == null)
currentfilename = "无标题";
if (currentfilename != "无标题")
{
File.WriteAllText(currentfilename, textBox1.Text);
}
else
{
另存为AToolStripMenuItem_Click(sender,e);
}
}
private void另存为AToolStripMenuItem_Click(object sender, EventArgs e) {
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
File.WriteAllText(saveFileDialog1.FileName, textBox1.Text);
setcurrentfilename(saveFileDialog1.FileName);
}
}
private void页面设置UToolStripMenuItem_Click(object sender, EventArgs e) {
this.pageSetupDialog1.Document = this.printDocument1;
if (this.pageSetupDialog1.ShowDialog() == DialogResult.OK)
{
this.printDocument1.Print();
}
}
{
PrintPreviewDialog printpreviewDialog = new PrintPreviewDialog();
printpreviewDialog.Document = this.printDocument1;
printpreviewDialog.ShowDialog();
}
private void退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void撤销UToolStripMenuItem_Click(object sender, EventArgs e)
{
textBox1.Undo();
}
private void剪切TToolStripMenuItem_Click(object sender, EventArgs e)
{
textBox1.Cut();
粘帖PToolStripMenuItem.Enabled = true;
}
private void复制CToolStripMenuItem_Click(object sender, EventArgs e)
{
textBox1.Copy();
粘帖PToolStripMenuItem.Enabled = true;
}
private void粘帖PToolStripMenuItem_Click(object sender, EventArgs e)
{
textBox1.Paste();
}
private void删除LToolStripMenuItem_Click(object sender, EventArgs e)
{
textBox1.SelectedText="";
}
private void查找FToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.mainform = this;
f2.Show();
}
private void查找下一个NToolStripMenuItem_Click(object sender, EventArgs e) {