using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace jcm
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void newfile_Click(object sender, EventArgs e)
        {
            richTextBox1.Enabled = true;
                                              //richTextBox1.Clear();
            richTextBox1.Focus();                                            //新建文件   

            if (MessageBox.Show("save?", "save file", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
            {

                this.saveFileDialog1.Filter = "txt files (*.txt)|*.txt|*.RTF Files|*.rtf|All files(*.)|*.*";
                this.saveFileDialog1.ShowDialog();
            }

        }

        private void openfile_Click(object sender, EventArgs e)
        {
            richTextBox1.Enabled = true;                                                                       //打开文件
            this.openFileDialog1.Filter = "txt files (*.txt)|*.txt|*.RTF Files|*.rtf|All files(*.)|*.*";
            this.openFileDialog1.ShowDialog();
        }

        private void savefile_Click(object sender, EventArgs e)
        {
            richTextBox1.Enabled = true;                                                                        //保存文件
            this.saveFileDialog1.Filter = "txt files (*.txt)|*.txt|*.RTF Files|*.rtf|All files(*.)|*.*";
            this.saveFileDialog1.ShowDialog();
        }

        private void savefile2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            richTextBox1.Enabled = true;                                                                        //保存文件
            this.saveFileDialog1.Filter = "txt files (*.txt)|*.txt|*.RTF Files|*.rtf|All files(*.)|*.*";
            this.saveFileDialog1.ShowDialog();
        }

        private void printpreview_Click(object sender, EventArgs e)
        {
            this.printPreviewDialog1.ShowDialog();                                                              //在对文件中的文字进行打印时所做的各种处理
        
        }

        private void print_Click(object sender, EventArgs e)
        {
            this.printDialog1.ShowDialog();                                                                    //对文件中的文字进行打印
        }

        private void pagesetup_Click(object sender, EventArgs e)
        {
            PageSetupDialog pageSetupDialog = new PageSetupDialog();
             pageSetupDialog.Document = printDocument1;
           // pageSetupDialog.ShowDialog();
        }

        private void exit_Click(object sender, EventArgs e)
        {
            this.Close();                                                                                      //退出对编辑器的各种操作
 
        }

        private void returnfile_Click(object sender, EventArgs e)
        {
            richTextBox1.Redo();                                                                               //撤消前一次操作
        
        }

        private void cut_Click(object sender, EventArgs e)
        {
            richTextBox1.Cut();                                                                                //对编辑区域中的文字进行剪切操作
        
        }

        private void copy_Click(object sender, EventArgs e)
        {
            richTextBox1.Copy();                                                                               //对编辑区域中的文字进行复制操作
       
        }

        private void paste_Click(object sender, EventArgs e)
        {
            richTextBox1.Paste();                                                                              //对编辑区域中的文字进行粘贴操作
        }

        private void delete_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();                                                                              //删除编辑区域的文字操作
        
        }

        private void fond_Click(object sender, EventArgs e)
        {

            jcm.Form2 from2= new jcm.Form2();
                                                                                                              //对文字中的特定文字进行查找
                 from2.Show();
      

                                                                                //对文字中的特定文字进行查找
            
        }

        private void selectAll_Click(object sender, EventArgs e)
        {
            richTextBox1.SelectAll();                                                                         //对编辑区域中的文字进行全选操作   
        }

        private void font_Click(object sender, EventArgs e)
        {
            if (this.fontDialog1.ShowDialog() == DialogResult.OK)
            {
                this.richTextBox1.Font = fontDialog1.Font;                                                    //对所编辑的文字进行字体和大小设置
            }
        }

        private void backcolor_Click(object sender, EventArgs e)
        {
            if (this.colorDialog1.ShowDialog() == DialogResult.OK)
            {
                this.richTextBox1.BackColor = colorDialog1.Color;                                             //对编辑区域进行背景颜色各种操作

            }
        }

        private void unit_Click(object sender, EventArgs e)
        {
          

        }

        private void returnfile2_Click(object sender, EventArgs e)
        {
            richTextBox1.Redo();                                                                               //撤消前一次操作
        
        }

        private void cut2_Click(object sender, EventArgs e)
        {
            richTextBox1.Cut();                                                                                //对编辑区域中的文字进行剪切操作
        
        }

        private void copy2_Click(object sender, EventArgs e)
        {
            richTextBox1.Copy();                                                                               //对编辑区域中的文字进行复制操作
       
        }

        private void paste2_Click(object sender, EventArgs e)
        {
            richTextBox1.Paste();                                                                              //对编辑区域中的文字进行粘贴操作
        }

        private void file_Click(object sender, EventArgs e)
        {

        }

        private void fontcolor_Click(object sender, EventArgs e)
        {
            if (this.colorDialog1.ShowDialog() == DialogResult.OK)
            {
                this.richTextBox1.ForeColor = colorDialog1.Color;                                            //对编辑区域进行字体颜色各种操作

            }
        }
        private int find(RichTextBox rtb1, string s1,int startindex)
        {
            string temp = rtb1.Text;
            return temp.IndexOf(s1, startindex);
        }
        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
           
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox2.Checked)
                richTextBox1.Font=new Font(richTextBox1.Font, richTextBox1.Font.Style | FontStyle.Italic);

            else                                                //设置字体的风格为倾斜


                richTextBox1.Font=new Font(richTextBox1.Font, richTextBox1.Font.Style ^ FontStyle.Italic);

        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
                richTextBox1.Font = new Font(richTextBox1.Font, richTextBox1.Font.Style | FontStyle.Bold);

            else                                                                                           //设置字体的风格为加粗

                richTextBox1.Font = new Font(richTextBox1.Font, richTextBox1.Font.Style ^ FontStyle.Bold);

        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {

            if (checkBox3.Checked)
                richTextBox1.Font = new Font(richTextBox1.Font, richTextBox1.Font.Style | FontStyle.Italic);

            else                                                //设置字体的风格为倾斜


                richTextBox1.Font = new Font(richTextBox1.Font, richTextBox1.Font.Style ^ FontStyle.Italic);

        }

        private void checkBox4_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox4.Checked)
                richTextBox1.Font = new Font(richTextBox1.Font, richTextBox1.Font.Style | FontStyle.Bold);

            else                                                                                           //设置字体的风格为加粗

                richTextBox1.Font = new Font(richTextBox1.Font, richTextBox1.Font.Style ^ FontStyle.Bold);

        }

        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void checkBox6_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox4.Checked)
                richTextBox1.Font = new Font(richTextBox1.Font, richTextBox1.Font.Style | FontStyle.Bold);

            else                                                                                           //设置字体的风格为加粗

                richTextBox1.Font = new Font(richTextBox1.Font, richTextBox1.Font.Style ^ FontStyle.Bold);

        }

        private void checkBox5_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox3.Checked)
                richTextBox1.Font = new Font(richTextBox1.Font, richTextBox1.Font.Style | FontStyle.Italic);

            else                                                //设置字体的风格为倾斜


                richTextBox1.Font = new Font(richTextBox1.Font, richTextBox1.Font.Style ^ FontStyle.Italic);

        }

        private void formfile_Click(object sender, EventArgs e)
        {

        }


        //     private void button1_Click(object sender, EventArgs e)
        //         {
        //             string str1;     //存放要查找的文本
        //             str1 = jcm.Form1.richTextBox1.Text;//获取要查找的文本
        //              jcm.Form1.StartPosition = jcm.Form1.richTextBox1.Find(str1, StartPosition, RichTextBoxFinds.MatchCase);//查找下一个
        //           if (jcm.Form1.StartPosition == 0)//如果返回-1,表示没有找到
        //           {
        //              MessageBox.Show("己替换到文本的结尾", "查找结束的对话框");//显示查找结束的对话框
        //              jcm.Form1.StartPosition = 0;//查找的位置为0,从头开始查找
        //            }
        //            else//查找到
        //                     jcm.Form1.StartPosition = jcm.Form1.StartPosition + str1.Length;//下一次查找的起始位置
        //                    jcm.Form1.richTextBox1.Focus();//为  richTextBox1设置焦点

        //           }
        //      private void richtextBox1_TextChanged(object sender, EventArgs e)//设置起始位置
        //            {
        //                 jcm.Form1StartPosition = 0;//只要查找的文本改变,则把 StartPosition的位置为0,重头开始查找
        //            }

        //      private void button2_Click(object sender, EventArgs e)
        //      {
        //        string str1;
        //        string str2;
        //        str1 = richTextBox3.Text;//获取要查找的文本
        //        str2 = richTextBox4.Text;//获取要替换的文本
        //         jcm.Form1.StartPosition = richTextBox3.Find(str1, StartPosition, RichTextBoxFinds.MatchCase);//查找下一个
        //         while (jcm.Form1.StartPosition != 0)//如果找到
        //        {
        //            richTextBox3.SelectedText = str2;//替换
        //            jcm.Form1.StartPosition = StartPosition + str2.Length;//下一次查找的起始位置
        //            jcm.Form1.StartPosition = richTextBox3.Find(str1, StartPosition, RichTextBoxFinds.MatchCase);//查找下一个
        //        }
        //          MessageBox.Show("己替换到文本的结尾", "查找结束的对话框");//显示查找结束的对话框
        //          StartPosition = 0;//查找的位置为0,从头开始查找
        //          jcm.Form1.richTextBox1.Focus();//为  richTextBox1设置焦点
        //      }

        //     private void button3_Click(object sender, EventArgs e)
        //       {

        //       }

        //     private void button4_Click(object sender, EventArgs e)
        //      {
        //        this.Close();
        //      }


        
    }
}