这种方法常常会用到,所以我在这写下来。 首先,创建Windows Forms 程序,然后在上面添加WebBrowser控件,代码如下: namespace WindowsFormsApplication { using System.Runtime.InteropServices; using System.Windows.Forms; public partial class Form1 : Form { [ComVisible(true)] public class ScriptManager { private Form1 mForm; public ScriptManager(Form1 form) { mForm = form; } public void MethodToCallFromScript() { mForm.DoSomething(); } public void AnotherMethod(string message) { MessageBox.Show(message); } } public void DoSomething() { MessageBox.Show("It worked!"); } public Form1() { InitializeComponent(); webBrowser1.Navigate("about:blank"); webBrowser1.ObjectForScripting = new ScriptManager(this); webBrowser1.Document.Write(@"<html> <head> <title>Test</title> </head> <body> <input type=""button"" value=""Go!"" οnclick=""window.external.MethodToCallFromScript();"" /> <br /> <input type=""button"" value=""Go Again!"" οnclick=""window.external.AnotherMethod('Hello');"" /> </body> </html>"); } } }