简体   繁体   English

在Web浏览器控件中单击URL即可打开Win表单

[英]Open win form on click of url within a webbrowser control

I have a Windows app where i use webbrowser control to show html text. 我有一个Windows应用程序,其中使用webbrowser控件显示html文本。 the problem is that i have some links in that html that i need them to open another win forms when user clicks them. 问题是我在该html中有一些链接,当用户单击它们时,我需要它们打开另一个胜利形式。

What I am suppose to write in the link 我想在链接中写些什么

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

or there is another method.please help. 或有另一种方法。请帮助。

Thanks for your time. 谢谢你的时间。

You can execute methods in your windows app by doing the following: First add permission, so add this above public class Form1 : Form 您可以通过执行以下操作在Windows应用程序中执行方法:首先添加权限,因此在公共类Form1上方添加以下内容:Form

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

Second you need to register your webbrowser control to have access to call your form functions, so add this to the Form_Load event 其次,您需要注册Webbrowser控件才能访问调用表单函数,因此将其添加到Form_Load事件中

this.WebBrowser1.ObjectForScripting = this;

Then you can create a Sub in your Main form. 然后,您可以在主窗体中创建一个Sub。 The sub MUST be Public. 该子项必须是公共的。

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

And in your HTML, do this: 然后在HTML中执行以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM