您的位置:首页 > Web前端 > JavaScript

JavaScript与C# Windows应用程序交互

2010-07-21 16:47 381 查看
转自http://www.cnblogs.com/xds/archive/2007/03/02/661838.html

一、建立网页

代码

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

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

System.IO.FileInfo file = new System.IO.FileInfo("index.htm");

// WebBrowser控件显示的网页路径

webBrowser1.Url = new Uri(file.FullName);

// 将当前类设置为可由脚本访问

webBrowser1.ObjectForScripting = this;

}

private void button1_Click(object sender, EventArgs e)

{

// 调用JavaScript的messageBox方法,并传入参数

object[] objects = new object[1];

objects[0] = "C#访问JavaScript脚本";

webBrowser1.Document.InvokeScript("messageBox", objects);

}

// 提供给JavaScript调用的方法

public void MyMessageBox(string message)

{

MessageBox.Show(message);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: