gpt4 book ai didi

c# - 检测 WebBrowser 控件上的滚动

转载 作者:太空狗 更新时间:2023-10-30 00:45:59 25 4
gpt4 key购买 nike

我有以下代码,奇怪的是,它工作了几秒钟然后停止工作(我的事件处理程序方法停止被调用):

public partial class Form1 : Form
{
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
webBrowser1.Navigate("google.com");
}

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (!webBrowser1.IsBusy && webBrowser1.Url == e.Url && webBrowser1.ReadyState == WebBrowserReadyState.Complete)
{
HTMLWindowEvents_Event windowEvents = webBrowser1.Document.Window.DomWindow as HTMLWindowEvents_Event;
windowEvents.onscroll += new HTMLWindowEvents_onscrollEventHandler(windowEvents_onscroll);
}
}

private void windowEvents_onscroll()
{
HtmlDocument htmlDoc = webBrowser1.Document;
int scrollTop = htmlDoc.GetElementsByTagName("HTML")[0].ScrollTop;
string text = scrollTop.ToString();
}
}

最佳答案

确定找到解决方案:

    protected override void OnDocumentCompleted(WebBrowserDocumentCompletedEventArgs e)
{
Follow();
if (!IsBusy && Url == e.Url && ReadyState == WebBrowserReadyState.Complete)
{
Document.Window.AttachEventHandler("onscroll", DocScroll);
}
}

如果以这种方式连接它就可以正常工作(到目前为止......)。甚至不需要使用 mshtml。

关于c# - 检测 WebBrowser 控件上的滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4343452/

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