Zoe

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

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

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
           textBox1.Text= textBox1.Text.Replace(textBox1.SelectedText,"");
        }

        private void 撤消UToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Undo();
        }

        private void 剪切TToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Cut();
        }

        private void 粘贴PToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Paste();
        }

        private void 复制CToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Copy();
        }

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

        private void 时间ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Text += DateTime.Now.ToString("HH:mm yyyy-MM-dd");
        }

        private void 查找ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2(this);
            f2.Owner = this;
            f2.Show();
        }

        private void 自动换行ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (textBox1.WordWrap)
            {
                textBox1.WordWrap = false;
                textBox1.ScrollBars = ScrollBars.Both;
            }
            else 
            {
                textBox1.WordWrap = true;
                textBox1.ScrollBars = ScrollBars.Vertical;
            }
        }

        private void 颜色ToolStripMenuItem_Click(object sender, EventArgs e)
        {

          DialogResult drr=  colorDialog1.ShowDialog();
            if(drr==DialogResult.OK)
            {
                textBox1.ForeColor = colorDialog1.Color;
            }
           
        }

        private void 字体ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult dr = fontDialog1.ShowDialog();
            if(dr==DialogResult.OK)
            {
                textBox1.Font = fontDialog1.Font;
            }
        }

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
          
        }
        string savepath = "";
        private void 保存SToolStripMenuItem_Click(object sender, EventArgs e)
        {

            if (savepath == "")

            {
                saveFileDialog1.FileName = "*.txt";
                saveFileDialog1.Filter = "文本文件|*.txt";
                DialogResult dr = saveFileDialog1.ShowDialog();
                if (dr == DialogResult.OK)
                {

                    StreamWriter sw = new StreamWriter(saveFileDialog1.FileName);
                    sw.Write(textBox1.Text);
                    sw.Flush();
                    sw.Close();
                    savepath = saveFileDialog1.FileName;
                }
            }
            else
            {
                StreamWriter sw = new StreamWriter(saveFileDialog1.FileName);
                sw.Write(textBox1.Text);
                sw.Flush();
                sw.Close();
                savepath = saveFileDialog1.FileName;

            }
        }

        private void 打开OToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "文本文件|*.txt|文档|*.doc|所有文件|*.*";
            DialogResult dr = openFileDialog1.ShowDialog();
            if (dr == DialogResult.OK)
            {

                StreamReader sr = new StreamReader(openFileDialog1.FileName, Encoding.Default);
                textBox1.Text = sr.ReadToEnd();
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            string str = ((TextBox)sender).Text;
            int count = str.Count();
            label_strcount.Text = "当前字符数量:" + count;

        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            pageSetupDialog1.Document = printDocument1;
           DialogResult dr= pageSetupDialog1.ShowDialog();
            if(dr==DialogResult.OK){}
        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Font f=new Font("黑体",20);
            Brush b = new SolidBrush(Color.Red);
            e.Graphics.DrawString(textBox1.Text,f,b,20,50);
        }

        private void printPreviewDialog1_Load(object sender, EventArgs e)
        {
        }

      
        private void 打印PToolStripMenuItem_Click(object sender, EventArgs e)
        {
            printDialog1.Document = printDocument1;
           DialogResult dr= printDialog1.ShowDialog();
            if(dr==DialogResult.OK)
            {
                printDocument1.Print();
            }
        }

        private void 打印预览VToolStripMenuItem_Click(object sender, EventArgs e)
        {

            printPreviewControl1.Document = printDocument1;

            printPreviewDialog1.Document = printDocument1;
            DialogResult dr = printPreviewDialog1.ShowDialog();
            if (dr == DialogResult.OK) { }
        }

      
    }
}

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

namespace WindowsFormsApplication3
{
    public partial class Form2 : Form
    {
        Form1 F1 = null;
        public Form2(Form1 f1)
        {
            InitializeComponent();
            F1 = f1;
        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }

        int count = 0;
        private void button1_Click(object sender, EventArgs e)
        {

           
            string s = textBox1.Text;
            count=F1.textBox1.Text.IndexOf(s,count);
            if (count < 0) { MessageBox.Show("未查到此字符串"); return; }
        
            F1.textBox1.Select(count,textBox1.Text.Length);
            F1.Focus();
            count++;
        }
    }
}

 

posted on 2017-05-03 15:25  口袋里的SKY  阅读(181)  评论(0编辑  收藏  举报