zoukankan      html  css  js  c++  java
  • 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++;
            }
        }
    }
  • 相关阅读:
    Key and Certificate Conversion
    openssl
    python http通信实现
    鼠标右键添加cmd
    好文章
    wireshark里无网络接口解决办法
    python垃圾回收
    终于有人把 Docker 讲清楚了
    mongodb的监控与性能优化
    mongodb创建超级用户和普通用户(对应数据库的用户)
  • 原文地址:https://www.cnblogs.com/zhengqian/p/6802113.html
Copyright © 2011-2022 走看看