Find, Find Next?

Posted by Tanner on Stack Overflow See other posts from Stack Overflow or by Tanner
Published on 2010-05-14T14:45:09Z Indexed on 2010/05/14 14:54 UTC
Read the original article Hit count: 584

Filed under:
|
|
|
|

Hello everyone, I am trying to make a find, find next function for my program, which I did manage to do with this code:

 int findPos = 0;
    private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            string s = textBox1.Text;
            richTextBox1.Focus();
            findPos = richTextBox1.Find(s, findPos, RichTextBoxFinds.None);
            richTextBox1.Select(findPos, s.Length);
            findPos += textBox1.Text.Length;
            //i = richTextBox1.Find(s, i + s.Length, RichTextBoxFinds.None);
        }
        catch
        {
            MessageBox.Show("No Occurences Found");
            findPos = 0;
        }
    }

And it works great in form1 but if I use this code and try to call it from form2 It doesn't do anything:

  //Form1
  public void FindNext()
    {
        try
        {
            this.Focus();
            Form2 frm2 = new Form2();
            string s = frm2.textBox1.Text;
            richTextBox1.Focus();
            findPos = richTextBox1.Find(s, findPos, RichTextBoxFinds.None);
            richTextBox1.Select(findPos + 1, s.Length);
            findPos += textBox1.Text.Length;
        }
        catch
        {
            MessageBox.Show("No Occurences Found");
            findPos = 0;
        }
    }

 //Form2
 private void button1_Click(object sender, EventArgs e)
    {
        Form1 frm1 = new Form1();
        frm1.FindNext();
    }

Does any one know why this is? Thanks,Tanner.

© Stack Overflow or respective owner

Related posts about find

Related posts about next