gpt4 book ai didi

c# - Webbrowser 查找上一个(文本)

转载 作者:太空宇宙 更新时间:2023-11-03 14:27:13 24 4
gpt4 key购买 nike

我正在尝试实现搜索例程:在 Webbrowser 中查找下一个和查找上一个。我知道里面有内置的查找对话框,但我不想使用它。相反,我正在努力编写自己的例程,但我无法通过。以下代码很好地实现了“查找下一个”:

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();
}

我完全无助于制作“查找上一个”例程。有天才可以锻造吗? (它可能与上面的非常相似)。

非常感谢

最佳答案

对于“查找上一个”例程,使用相同的代码并进行 2 处修改:1) 将 tr.collapse 的参数从 false 更改为 true;2) 将tr.findText的第二个参数从1改为-1。

所以这些行将是:

tr.collapse(true); // use true to move caret at the beginning of the current selection
tr.findText(s, -1, 0); // positive value, should search forward, negative backward

关于c# - Webbrowser 查找上一个(文本),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3588350/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com