界面示例(上方为仿制窗口,下方为记事本窗口):
能正常实现循环、区分大小写、向上搜索、向下搜索、向搜索框内填充内容等操作
相关代码(仅逻辑代码):
using System;
using System.Windows.Forms;
namespace FindImitate
{
public partial class FindForm : Form
{
/// <summary>
/// 是否大小写
/// </summary>
private static bool _isMatchCase = true;
/// <summary>
/// 是否循环
/// </summary>
private static bool _isCycle;
/// <summary>
/// 搜索方向,true为向上,false为向下
/// </summary>
private static bool _direction;
/// <summary>
/// 是否为第二次寻找
/// </summary>
private bool _seekAgain;
/// <summary>
/// 上次搜索的内容
/// </summary>
private static string _lastFindText = "";
/// <summary>
/// 富文本框对象
/// </summary>
private readonly RichTextBox _richTextBox;
/// <summary>
/// 含参的构造函数
/// </summary>
/// <param name="richTextBox">富文本框</param>
public FindForm(RichTextBox richTextBox)
{
InitializeComponent();
// 传入对象
_richTextBox = richTextBox;
// 注册关闭事件
FormClosed += FindForm_Closed;
// 先把按钮状态设置一下
checkBox1.Checked = _isMatchCase;
chec