tags:

views:

25

answers:

0

Hi,

I am trying to implement search routines: Find Next and Find Previous in Webbrowser. I know that there is Build-in Find dialog inside, but I do not want to use it. Instead I am trying hard to write my own routines, but I can not get through. Following code implements "Find next" nicely:

using mshtml;

....

private void toolStripButton5_Click(object sender, EventArgs e)
        {
            IHTMLDocument2 htmlDocument = WB.Document.DomDocument as IHTMLDocument2;
            IHTMLSelectionObject sel = (IHTMLSelectionObject)htmlDocument.selection;
            IHTMLTxtRange tr = (IHTMLTxtRange)sel.createRange() as IHTMLTxtRange;
            string s = toolStripTextBox1.Text;
            tr.collapse(false); 
            tr.findText(s, 1, 0); // positive value, should search forward, negative backward
            tr.select();
        }

I am totaly helpless making "Find previous" routine. Can any genius forge it? (it will be probably very similar to that above).

Thanks very much