欢迎来到天天文库
浏览记录
ID:16531129
大小:57.00 KB
页数:6页
时间:2018-08-22
《多文档文本编辑器代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、多文档文本编辑器代码usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.IO;namespaceWindowsApplication1{publicpartialclassForm1:Form{privatestringcurrentfilename;
2、publicstringmainkey=null;publicboolMaxOrMin;//处理文件名子程序privatevoidsetcurrentfilename(stringfilepath){currentfilename=filepath;this.Text=Path.GetFileName(currentfilename)+"-记事本";}//窗口初始化程序publicForm1(){InitializeComponent();撤销UToolStripMenuItem.Enabled=false;复制CToo
3、lStripMenuItem.Enabled=false;剪切TToolStripMenuItem.Enabled=false;删除LToolStripMenuItem.Enabled=false;if(Clipboard.ContainsText()==true){粘帖PToolStripMenuItem.Enabled=true;}else{粘帖PToolStripMenuItem.Enabled=false;}}privatevoid新建NToolStripMenuItem_Click(objectsender,E
4、ventArgse){textBox1.Text="";setcurrentfilename("无标题");}privatevoid打开ToolStripMenuItem_Click(objectsender,EventArgse){if(openFileDialog1.ShowDialog()==DialogResult.OK){setcurrentfilename(openFileDialog1.FileName);textBox1.Text=File.ReadAllText(currentfilename);}}p
5、rivatevoid保存SToolStripMenuItem_Click(objectsender,EventArgse){if(currentfilename==null)currentfilename="无标题";if(currentfilename!="无标题"){File.WriteAllText(currentfilename,textBox1.Text);}else{另存为AToolStripMenuItem_Click(sender,e);}}privatevoid另存为AToolStripMenuItem
6、_Click(objectsender,EventArgse){if(saveFileDialog1.ShowDialog()==DialogResult.OK){File.WriteAllText(saveFileDialog1.FileName,textBox1.Text);setcurrentfilename(saveFileDialog1.FileName);}}privatevoid页面设置UToolStripMenuItem_Click(objectsender,EventArgse){this.pageSe
7、tupDialog1.Document=this.printDocument1;if(this.pageSetupDialog1.ShowDialog()==DialogResult.OK){this.printDocument1.Print();}}privatevoid打印PToolStripMenuItem_Click(objectsender,EventArgse){PrintPreviewDialogprintpreviewDialog=newPrintPreviewDialog();printpreviewD
8、ialog.Document=this.printDocument1;printpreviewDialog.ShowDialog();}privatevoid退出ToolStripMenuItem_Click(objectsender,EventArgse){Application.Exit();}privatevo
此文档下载收益归作者所有