2017-5-3 记事本制作

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++;
        }
    }
}

 

转载于:https://www.cnblogs.com/zhengqian/p/6802113.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值