C#记事本

  1. <font size="4" color="#ff0000"><strong><u>没找到上传压缩文件的按钮,只好把源代码上传到这里了.<img alt="" src="/Editor/FCKeditor/editor/images/smiley/msn/regular_smile.gif"></u></strong></font>  
没找到上传压缩文件的按钮,只好把源代码上传到这里了.
  1. <strong><u><font size="4" color="#ff0000">注释很详细哦</font></u></strong>  
注释很详细哦
  1. <font size="4" color="#ff0000"><strong><u>Form1.cs   </u></strong></font><strong><u><font size="4" color="#ff0000">************************************************</font></u></strong>  
Form1.cs   ************************************************
  1. using System;  
  2.   
  3. using System.Collections.Generic;  
  4.   
  5. using System.ComponentModel;  
  6.   
  7. using System.Data;  
  8.   
  9. using System.Drawing;  
  10.   
  11. using System.Text;  
  12.   
  13. using System.Windows.Forms;  
  14.   
  15. using System.IO;  
  16.   
  17.   
  18.   
  19. namespace txttest  
  20.   
  21. {  
  22.   
  23.     public partial class Form1 : Form  
  24.   
  25.     {  
  26.   
  27.         public Form1()  
  28.   
  29.         {  
  30.   
  31.             InitializeComponent();  
  32.   
  33.         }  
  34.   
  35.         /******************************************************************/  
  36.   
  37.         /******************************************************************/  
  38.   
  39.         /******************************************************************/  
  40.   
  41.         /******************************************************************/  
  42.  
  43.         #region 定义变量  
  44.   
  45.         public bool txtchange; //定义用于检查文本是否改变的变量  
  46.   
  47.         public bool save;      //定义bool类型Save判断用户选择得是SaveFile()还是SaveAsFile()  
  48.   
  49.         Search sea;       //声明查找的成员  
  50.   
  51.         Change cha;            //声明替换的成员  
  52.  
  53.         #endregion  
  54.   
  55.         #region 文件菜单  
  56.   
  57.         //新建  
  58.   
  59.         private void MnuNew_Click(object sender, EventArgs e)  
  60.   
  61.         {  
  62.   
  63.             NewFile();  
  64.   
  65.         }  
  66.   
  67.         //打开  
  68.   
  69.         private void MnuOpen_Click(object sender, EventArgs e)  
  70.   
  71.         {  
  72.   
  73.             OpenFile();  
  74.   
  75.         }  
  76.   
  77.         //保存  
  78.   
  79.         private void MnuSave_Click(object sender, EventArgs e)  
  80.   
  81.         {  
  82.   
  83.             save = true;  
  84.   
  85.             SaveFile();  
  86.   
  87.         }  
  88.   
  89.         //另存为  
  90.   
  91.         private void MnuSaveAs_Click(object sender, EventArgs e)  
  92.   
  93.         {  
  94.   
  95.             save = false;  
  96.   
  97.             SaveFile();  
  98.   
  99.         }  
  100.   
  101.         //页面设置  
  102.   
  103.         private void MnuPageSetup_Click(object sender, EventArgs e)  
  104.   
  105.         {  
  106.   
  107.             pageSetupDialog1 = new PageSetupDialog();     //初始化pageSetupDialog1的新实例  
  108.   
  109.             pageSetupDialog1.Document = printDocument;    //获取或设置一个值,指示从中获取页面设置  
  110.   
  111.             pageSetupDialog1.ShowDialog();                //弹出页面设置对话框  
  112.   
  113.         }  
  114.   
  115.         //打印预览  
  116.   
  117.         private void MnuPringPreview_Click(object sender, EventArgs e)  
  118.   
  119.         {  
  120.   
  121.             printPreviewDialog.ShowDialog();          //调用系统的打印预览对话框  
  122.   
  123.         }          
  124.   
  125.         //打印  
  126.   
  127.         private void MnuPrint_Click(object sender, EventArgs e)  
  128.   
  129.         {  
  130.   
  131.             printDocument.DocumentName = richTextBox1.Text;    //获取打印得文档名  
  132.   
  133.             printDialog.Document = printDocument;              //打印对话框  
  134.   
  135.             if (printDialog.ShowDialog() == DialogResult.OK)   //点击打印的确定按钮==OK  
  136.   
  137.             {  
  138.   
  139.                 //异常处理  
  140.   
  141.                 try   
  142.   
  143.                 {  
  144.   
  145.                     printDocument.Print();                     //try 打印时是否出错  
  146.   
  147.                 }  
  148.   
  149.                 catch(Exception ex)  
  150.   
  151.                 {  
  152.   
  153.                     MessageBox.Show(ex.Message);               //出错则弹出系统定义的错误信息  
  154.   
  155.                 }  
  156.   
  157.             }     
  158.   
  159.         }  
  160.   
  161.         //退出  
  162.   
  163.         private void MnuExit_Click(object sender, EventArgs e)  
  164.   
  165.         {  
  166.   
  167.             DialogResult res;            //实例化对话框的结果按钮为res=OK,Cancle  
  168.   
  169.             res = MessageBox.Show("确定退出记事本?""退出提示", MessageBoxButtons.OKCancel);  
  170.   
  171.             if (res == DialogResult.OK)  
  172.   
  173.             {  
  174.   
  175.                 //判断文件是否修改过   包括空格  
  176.   
  177.                 if (txtchange)  
  178.   
  179.                 {  
  180.   
  181.                     DialogResult re;     //实例化对话框的结果按钮为res=Yes,No,Cancle  
  182.   
  183.                     re = MessageBox.Show("内容已更改/n是否保存?""保存提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);  
  184.   
  185.   
  186.   
  187.                     if (re == DialogResult.Yes)  
  188.   
  189.                     {  
  190.   
  191.                         if (saveFileDialog.ShowDialog() == DialogResult.OK)//点击保存文件对话框得OK时执行下面  
  192.   
  193.                         {  
  194.   
  195.                             //获取将要保存的文件名,并将其中的文件获取并保存  
  196.   
  197.                             richTextBox1.SaveFile(saveFileDialog.FileName, RichTextBoxStreamType.PlainText);  
  198.   
  199.                             Close();     //保存并退出  
  200.   
  201.                               
  202.   
  203.                         }  
  204.   
  205.                         else  
  206.   
  207.                             return;      //返回至编辑界面  
  208.   
  209.                     }  
  210.   
  211.                     else if (re == DialogResult.No)  
  212.   
  213.                     {  
  214.   
  215.                         Close();         //不保存退出  
  216.   
  217.                     }  
  218.   
  219.                     else  
  220.   
  221.                     {  
  222.   
  223.                         return;          //返回至编辑界面  
  224.   
  225.                     }  
  226.   
  227.                 }  
  228.   
  229.                 else  
  230.   
  231.                     Close();             //文件没有被修改过,直接退出  
  232.   
  233.             }  
  234.   
  235.             else  
  236.   
  237.   
  238.   
  239.                 return;                  //返回至编辑界面  
  240.   
  241.         }  
  242.   
  243.   
  244.   
  245.         //检查txtbox中内容是否有更改  
  246.   
  247.         private 
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值