第一篇,winform窗体嵌套在html页面中,使用js调用

js代码:

function openwin(name) {

document.getElementById('testwin').innerHTML = window.external.test();

}

C#代码:

winform中,首先 加入 [System.Runtime.InteropServices.ComVisibleAttribute(true)]

[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]

[System.Runtime.InteropServices.ComVisibleAttribute(true)]

public partial class Win : Form

{

private void Win_Load(object sender, EventArgs e)

{

this.browser.ObjectForScripting = this;

}

   public string test() { return "test"; }//被js调用的公共方法

}