【问题标题】:Open win form on click of url within a webbrowser control在 webbrowser 控件中单击 url 打开 win 表单
【发布时间】:2014-09-26 21:29:18
【问题描述】:

我有一个 Windows 应用程序,我在其中使用 webbrowser 控件来显示 html 文本。 问题是我在该 html 中有一些链接,当用户单击它们时,我需要它们打开另一个 win 表单。

我想在链接中写什么

<a href:????> click to show another win form</a>

或者还有其他方法。请帮忙。

感谢您的宝贵时间。

【问题讨论】:

  • 您要查找的内容称为WebBrowser 控件的ObjectForScripting 属性。查看this link 了解更多信息和示例。

标签: c# html windows-applications web-controls


【解决方案1】:

您可以通过执行以下操作在 Windows 应用程序中执行方法: 首先添加权限,所以在公共类Form1上面添加这个:Form

[PermissionSet(SecurityAction.Demand, Name="FullTrust")]
[System.Runtime.InteropServices.ComVisibleAttribute(true)]

其次,您需要注册您的 webbrowser 控件以有权调用您的表单函数,因此将其添加到 Form_Load 事件中

this.WebBrowser1.ObjectForScripting = this;

然后你可以在你的 Main 表单中创建一个 Sub。子必须是公开的。

public void doOpenForm()
{
    //your code to open the form here
}

在你的 HTML 中,这样做:

<a href='' onclick='window.external.doOpenForm()'> click to show another win form</a>

【讨论】:

  • 没错,它很容易翻译成 C#...概念是一样的,只是语法不同
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多