form2.cs

来自「编辑简单的文本编辑器」· CS 代码 · 共 36 行

CS
36
字号
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TextEditor
{
   public partial class Form2 : Form
    {
        public int start;
        public RichTextBox s1; 
        public Form2()
        {
            InitializeComponent();
        }

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

        }
    }       
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?