using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NotePad
{
    public partial class frmFind : Form
    {
        public frmFind()
        {
            InitializeComponent();
        }
        int index;
        private void button1_Click(object sender, EventArgs e)
        {
            string str = txtFind.Text;
            try
            {
                int starting = (Application.OpenForms["Form1"].Controls["richTextBox1"] as RichTextBox).Text.IndexOf(str, index);
                (Application.OpenForms["Form1"].Controls["richTextBox1"] as RichTextBox).Select(starting, str.Length);
                (Application.OpenForms["Form1"].Controls["richTextBox1"] as RichTextBox).Focus();
                index = starting + str.Length;
            }
            catch
            {
                MessageBox.Show("جستجو به پایان رسید");
            }
        }
    }
}
