制作记事本

制作记事本

添加一个menustrip  再添加一个textbox用于写文字

撤销   textBox1.Undo();

剪切  textBox1.Cut();

复制   textBox1.Copy();

粘贴  textBox1.Paste();

删除  textBox1.Text = textBox1.Text.Replace(textBox1.SelectedText, ""); 没有删除方法 将选中的内容替换成空格

全选   textBox1.SelectAll();

时间   textBox1.Text += DateTime.Now.ToString("HH:mm yyy/MM/dd");

查找    打开一个新窗口

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("找不到“" + s + "");
            }
            else
            {
                F1.textBox1.Select(count, textBox1.Text.Length);
                F1.Focus();
               
            }
            if (count < 0)
            {
                count = 0;
            }
            else
            { count++; }
            
         }

循环查找代码

 

自动换行     自动换行checked

if (textBox1.WordWrap)
            {
                textBox1.WordWrap = false;
                textBox1.ScrollBars = ScrollBars.Both;
            }
            else
            {
                textBox1.WordWrap = true;
                textBox1.ScrollBars = ScrollBars.Vertical;
            }

 

颜色  

DialogResult drr = colorDialog1.ShowDialog();

            if (drr == DialogResult.OK)       

      {                 textBox1.ForeColor = colorDialog1.Color;             }

 

字体    字体也可以控制颜色  在字体属性里面有个颜色开关属性

DialogResult dr = fontDialog1.ShowDialog();          

   if (dr == DialogResult.OK)       

      {                 textBox1.Font = fontDialog1.Font;      

           textBox1.ForeColor = fontDialog1.Color;

            }

 

 

打开文件

openFileDialog1.Filter = "文本文件|*.txt";

            DialogResult dr = openFileDialog1.ShowDialog();  

           if (dr == DialogResult.OK)         

    {                 StreamReader sr = new StreamReader(openFileDialog1.FileName, Encoding.Default);  

               textBox1.Text = sr.ReadToEnd();

            }

保存文件        需要先定义一个空字符串 满足if则不需要再次打开保存位置

另存为    无论如何都要打开保存位置

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

 

posted @ 2017-05-03 16:32  v587yy  阅读(352)  评论(0编辑  收藏  举报