c# - 如何在事件处理程序内调用 WebBrowser 上的方法?

标签 c# .net events webbrowser-control

这是我的:

public void initiate(WebBrowser browser)
{         
   browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(refDocumentCompleted);
   // navigate browser to the referal Uri
   browser.Navigate(refreral);

   browser.DocumentCompleted -= refDocumentCompleted;
   //remove here so that it doesn't do this everytime a document is completed, i want it just in this method
}

private void refDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    // want to call navigate method on browser here. but Its out of scope.
}

我希望它做的是,导航到 referral,然后在加载后导航到另一个页面,该页面存储为类中的全局字符串。

我确定我在这里的麻烦是由于对事件如何运作的理解不足,我已经尝试阅读它,但似乎无法理解它但我认为我不需要创建我自己的处理程序。

最佳答案

您已经有了 webbrowser 对象。你只需要施放它:

((WebBrowser)sender).Navigate(...);

等等

关于c# - 如何在事件处理程序内调用 WebBrowser 上的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12326509/

相关文章:

.net - MVC4 HTTP 错误 403.14 - 禁止

delphi - 如何比较一个事件及其相应的过程,避免E2035和E2036?

javascript - 如何检查事件是否被阻止

c# - 将 List<> 转换为 Array - 我得到 "Attempted to access an element as a type incompatible with the array."

c# - 我们可以在 C# 中使用多线程将 Microsoft Word 文档转换为 HTML 吗?

c# - 异步等待和线程

javascript - 当鼠标在 DOM 元素内移动时,如何防止执行 mouseover 函数 - Backbone Events

c# - 在 C# 中使用 iTextSharp 和 asp 图像调整数据库中的图像大小

c# - 如何使用 unity + UnityAutoRegistration 进行开放式通用装饰器链接

.net - WCF:如何从 ServiceHost 获取端点列表?