基本信息
源码名称:C# 高仿windows 记事本 程序源码
源码大小:0.44M
文件格式:.rar
开发语言:C#
更新时间:2016-10-19
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

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.Runtime.InteropServices;
using System.Drawing.Printing;


namespace Mynotepad
{
    public partial class Form1 : Form
    {
        string fileAddress;
        bool istextChanged = false;
        bool isopenFile = false;
        public static Form1 notepad;
        private Form3 fm3;
        public Form1()
        {
            InitializeComponent();
            fm3 = new Form3();
            fm3.Owner = this;
        }
        [STAThread]
        static void Main()
        {
           
            notepad = new Form1();
            Application.EnableVisualStyles();
           //Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(notepad);
        }
        private void new_Click(object sender, EventArgs e)
        {
            if (this.richTextBox1.Text != "")
            {
                // DialogResult strYesNoCancel = MessageBox.Show("文件的内容已改变,是否保存", "记事本", MessageBoxButtons.YesNoCancel);
                DialogResult strYesNoCancel = MessageBox.Show("文件"   Text   "的内容已改变,需要保存吗?", "保存文件",
                    MessageBoxButtons.YesNoCancel);
                if (strYesNoCancel.ToString() == "Yes")
                {
                    saveFileDialog1.Reset();
                    saveFileDialog1.Filter = "文本文件(*.txt)|*.txt";
                    saveFileDialog1.Title = "另存为";
                    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
                        fileAddress = saveFileDialog1.FileName;
                    }
                }
                if (strYesNoCancel.ToString() == "No")
                {
                    this.richTextBox1.Clear();
                    this.Text = "新建文本"   "-记事本";
                }
                if (strYesNoCancel.ToString() == "Cancel")
                {
                    return;
                }
            }
            else
            {
                this.richTextBox1.Clear();
                this.Text = "新建文本"   "-记事本";
            }

        }

        private void 打开OToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.Reset();
            openFileDialog1.Filter = "文本文件(*.txt)|*.txt|所有文件|*";
            openFileDialog1.CheckFileExists = true;
            openFileDialog1.CheckPathExists = true;
            openFileDialog1.Multiselect = false;
            openFileDialog1.Title = "打开文件";
            if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);
                isopenFile = true;
                istextChanged = false;
                this.Text = Path.GetFileName(openFileDialog1.FileName)   "-记事本";
                fileAddress = openFileDialog1.FileName;
            }

        }

        private void 另存为AToolStripMenuItem_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Reset();
            saveFileDialog1.Filter = "文本文件(*.txt)|*.txt";
            saveFileDialog1.Title = "另存为";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                 richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
                 fileAddress = saveFileDialog1.FileName;
            }
        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            toolStripButton6.Enabled = true;
            撤消UToolStripMenuItem.Enabled = true;
            撤消ToolStripMenuItem.Enabled = true;
            istextChanged = true;
        }

        private void 保存SToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (isopenFile)
            {
                if (istextChanged)
                {
                    richTextBox1.SaveFile(fileAddress, RichTextBoxStreamType.PlainText);
                    
                }
            }
            else
            {
                if (istextChanged)
                {
                    saveFileDialog1.Reset();
                    saveFileDialog1.Filter = "文本文件(*.txt)|*.txt";
                    saveFileDialog1.Title = "另存为";
                    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
                        fileAddress = saveFileDialog1.FileName;
                    }
                }
            }

        }

        private void 字体FToolStripMenuItem_Click(object sender, EventArgs e)
        {
            fontDialog1.ShowColor = true;
            fontDialog1.ShowApply = false;
            fontDialog1.ShowEffects = true;
            if (fontDialog1.ShowDialog(this) == DialogResult.OK)
            {
                richTextBox1.Font = fontDialog1.Font;
                richTextBox1.ForeColor = fontDialog1.Color;
            }
        }

        private void toolStripButton16_Click(object sender, EventArgs e)
        {
            colorDialog1.AnyColor = true;
            colorDialog1.AllowFullOpen = true;
            colorDialog1.FullOpen = true;
            if (colorDialog1.ShowDialog(this) == DialogResult.OK)
            {
                richTextBox1.ForeColor = colorDialog1.Color;
            }
        }

       

        private void 撤消UToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (richTextBox1.CanUndo == true)
            {
                richTextBox1.Undo();
                toolStripButton7.Enabled = true;
                toolStripMenuItem1.Enabled = true;
                toolStripButton6.Enabled = false;
                撤消UToolStripMenuItem.Enabled = false;
                撤消ToolStripMenuItem.Enabled = false ;
                //textBox1.ClearUndo(); 
            } 
        }


        private void 重做toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (richTextBox1.CanRedo == true)
            {
                richTextBox1.Redo();
                toolStripButton7.Enabled = false;
                toolStripMenuItem1.Enabled = false;
            } 
        }

        private void 剪切TToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (richTextBox1.SelectedText != "")
            {
                richTextBox1.Cut();
            }
        }

        private void 复制CToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (richTextBox1.SelectedText != "")
            {
                richTextBox1.Copy();
            } 
        }

        private void 粘贴PToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) == true)
            {
                richTextBox1.Paste();
            } 
        }

        private void 删除LToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (richTextBox1.SelectedText != "")
            {
                richTextBox1.SelectedText = "";
            } 
        }

     

        private void 时间日期DToolStripMenuItem_Click(object sender, EventArgs e)
        {
           // richTextBox1.AppendText(DateTime.Now.ToString()); 
            richTextBox1.SelectedText = DateTime.Now.ToString();

        }

        private void 全选AToolStripMenuItem_Click(object sender, EventArgs e)
        {
            richTextBox1.SelectAll(); 
        }

      

        private void toolStripButton17_Click(object sender, EventArgs e)
        {
            ColorDialog colorDialog1 = new ColorDialog();
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                richTextBox1.BackColor = colorDialog1.Color;
            } 
        }

        private void 状态ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (状态ToolStripMenuItem.Checked == true)
            {
                statusStrip1.Visible = false;
                状态ToolStripMenuItem.Checked = false;
                 
            }
            else
            {
                statusStrip1.Visible = true;
                状态ToolStripMenuItem.Checked = true;
                 
            } 
        }
        private void richTextBox1_SelectionChanged(object sender, EventArgs e)
        {
            if (richTextBox1.SelectionLength == 0)
            {
                toolStripButton5.Enabled = false;
                toolStripButton8.Enabled = false;
                toolStripButton10.Enabled = false;
                剪切TToolStripMenuItem.Enabled = false;
                复制CToolStripMenuItem.Enabled = false;
                删除LToolStripMenuItem.Enabled = false;
                剪切ToolStripMenuItem.Enabled = false;
                复制ToolStripMenuItem.Enabled = false;
                删除ToolStripMenuItem.Enabled = false;
                toolStripButton14.Enabled = false;
                toolStripButton15.Enabled = false;
                toolStripButton20.Enabled = false;
            }
            else
            {
                toolStripButton5.Enabled = true;
                toolStripButton8.Enabled = true;
                toolStripButton10.Enabled = true;
                剪切TToolStripMenuItem.Enabled = true;
                复制CToolStripMenuItem.Enabled = true;
                删除LToolStripMenuItem.Enabled = true;
                剪切ToolStripMenuItem.Enabled = true;
                复制ToolStripMenuItem.Enabled = true;
                删除ToolStripMenuItem.Enabled = true;
                toolStripButton14.Enabled = true;
                toolStripButton15.Enabled = true;
                toolStripButton20.Enabled = true;
            }

             if (状态ToolStripMenuItem.Enabled == true)
            {
                if (状态ToolStripMenuItem.Checked == true)
                {
                    status(sender, e);
                }
                else
                {
                    toolStripStatusLabel1.Text = "";
                }
            }
        } 
        private void status(object sender, EventArgs e)
        {
            int line = this.richTextBox1.GetLineFromCharIndex(richTextBox1.SelectionStart);
            int col;
            int start = 0;
            int cursor = richTextBox1.SelectionStart;
            while (start < cursor)
            {
                if (line == this.richTextBox1.GetLineFromCharIndex(start))
                {
                    break;
                }
                else
                    start  ;
            }
            col = cursor - start;
            line  ;
            col  ;
            toolStripStatusLabel1.Text = " 行数"   line   "列"   col ;
        }

        private void 自动换行WToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (自动换行WToolStripMenuItem.Checked == true)
            {
                自动换行WToolStripMenuItem.Checked = false;
                toolStripMenuItem2.Enabled = true;
                richTextBox1.ScrollBars = RichTextBoxScrollBars.ForcedBoth;
                richTextBox1.WordWrap = false;
            }
            else
            {
                toolStripMenuItem2.Enabled = false;
                自动换行WToolStripMenuItem.Checked = true;
                richTextBox1.ScrollBars = RichTextBoxScrollBars.ForcedVertical;
                richTextBox1.WordWrap = true;
            } 
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Text = "无标题"   "-记事本";
            this.TopMost = false;
        }

        private void 关于AToolStripMenuItem_Click(object sender, EventArgs e)
        {
            About about = new About();
            about.Show();
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.richTextBox1.Text != "")
            {
                e.Cancel = true;
                DialogResult strYesNoCancel = MessageBox.Show("文件"   Text   "的内容已改变,需要保存吗?", "保存文件",
                    MessageBoxButtons.YesNoCancel);
                if (strYesNoCancel.ToString() == "Yes")
                {
                    saveFileDialog1.Reset();
                    saveFileDialog1.Filter = "文本文件(*.txt)|*.txt";
                    saveFileDialog1.Title = "另存为";
                    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
                        e.Cancel = false;

                    }
                }
                if (strYesNoCancel.ToString() == "No")
                {
                    e.Cancel = false;
                }
                if (strYesNoCancel.ToString() == "Cancel")
                {
                    return;
                }
            }
        }

        private void 退出XToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.richTextBox1.Text != "")
            {

                DialogResult strYesNoCancel = MessageBox.Show("文件"   Text   "的内容已改变,需要保存吗?", "保存文件",
                    MessageBoxButtons.YesNoCancel);
                if (strYesNoCancel.ToString() == "Yes")
                {
                    saveFileDialog1.Reset();
                    saveFileDialog1.Filter = "文本文件(*.txt)|*.txt";
                    saveFileDialog1.Title = "另存为";
                    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
                        this.Dispose();
                    }
                }
                if (strYesNoCancel.ToString() == "No")
                {
                    this.Dispose();
                     
                }
                if (strYesNoCancel.ToString() == "Cancel")
                {
                    return;
                }
            }
            else
            {
                this.Dispose();
            }
        }
        private void toolStripButton14_Click(object sender, EventArgs e)    //粗体
        {
            if (richTextBox1.SelectionFont != null)
            {
                System.Drawing.Font currentFont = richTextBox1.SelectionFont;
                System.Drawing.FontStyle newFontStyle;

                if (richTextBox1.SelectionFont.Bold == true)
                {
                    newFontStyle = FontStyle.Regular;
                }
                else
                {
                    newFontStyle = FontStyle.Bold;
                }

                richTextBox1.SelectionFont = new Font(
                   currentFont.FontFamily,
                   currentFont.Size,
                   newFontStyle
                );
            }

        }
        private void toolStripButton15_Click(object sender, EventArgs e)    //斜体
        {
            if (richTextBox1.SelectionFont != null)
            {
                System.Drawing.Font currentFont = richTextBox1.SelectionFont;
                System.Drawing.FontStyle newFontStyle;

                if (richTextBox1.SelectionFont.Italic == true)
                {
                    newFontStyle = FontStyle.Regular;
                }
                else
                {
                    newFontStyle = FontStyle.Italic;
                }

                richTextBox1.SelectionFont = new Font(
                   currentFont.FontFamily,
                   currentFont.Size,
                   newFontStyle
                );
            }
        }
        private void toolStripButton20_Click(object sender, EventArgs e)    //下滑线
        {
            if (richTextBox1.SelectionFont != null)
            {
                System.Drawing.Font currentFont = richTextBox1.SelectionFont;
                System.Drawing.FontStyle newFontStyle;

                if (richTextBox1.SelectionFont.Underline == true)
                {
                    newFontStyle = FontStyle.Regular;
                }
                else
                {
                    newFontStyle = FontStyle.Underline;
                }

                richTextBox1.SelectionFont = new Font(
                   currentFont.FontFamily,
                   currentFont.Size,
                   newFontStyle
                );
            }
        }
        private void richTextBox1_LinkClicked(object sender, LinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start(e.LinkText);
        }
        private void richTextBox1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
        {
            string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, true);
            int i;
            for (i = 0; i < s.Length; i  )
                fileAddress = s[i];
            richTextBox1.LoadFile((string)fileAddress, RichTextBoxStreamType.PlainText);
            isopenFile = true;
        }  

        public static void gto(int i)
        {
            //光标的焦点的行数
            int ln = 0;
            for (int count = 0; count < i; count  )
            {
                foreach (char ch in notepad.richTextBox1.Lines[count])
                {
                    ch.ToString();
                    ln  ;
                }
                ln  = 1;   //表示一个换行符 占二个字符
            }
            notepad.richTextBox1.SelectionStart = ln;
            notepad.richTextBox1.ScrollToCaret();

        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            int line = this.richTextBox1.Lines.Length;
            if (line == 0)
            {
                line = line   1;
               
            }
            Goto go = new Goto(line);
            go.ShowDialog();
        }

       

        private void toolStripButton11_Click(object sender, EventArgs e)
        {
            if (this.TopMost == true)
            {
                this.TopMost = false;
                return;
                
            }
            else
            {
                this.TopMost = true;
                return;
            } 
        }

        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            if (fm3.IsDisposed)
            {
                fm3 = new Form3();
                fm3.Owner = this; 
                fm3.Show();
            }
            else
            {
                fm3.Show();
            }
        }

        private void 帮助HToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Form4 form4 = new Form4();
            form4.Show();
        }

        
    
 }
}