winform程序里有webbrower控件,嵌套这一个web程序,现在要想再web程序做的操作能让winform知道,
或者webbrower控件里的web程序如何调用winform里的方法。?
有demo最好了。谢谢各位,急求

解决方案 »

  1.   


    using System.Windows.Forms;namespace WindowsFormsApplication2
    {
        [System.Runtime.InteropServices.ComVisibleAttribute(true)]
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                webBrowser1.ObjectForScripting = this;            webBrowser1.Navigate("about:blank");
                webBrowser1.Document.Write(@"<script type=""text/javascript""> function WinFormShowMsg(text) {    window.external.ShowMsg(text);}</script>  <input id='ShowMsg' type='button' onClick='WinFormShowMsg(""www"");' >");
            }        public void ShowMsg(string text)
            {
                MessageBox.Show("WinForm弹出:" + text);
            }
        }
    }
    使用window.external
    测试上面的代码
    有两点需要注意:
    1.[System.Runtime.InteropServices.ComVisibleAttribute(true)]
    2.webBrowser1.ObjectForScripting = this;
      

  2.   

    楼上正解,其实winfrom中调用webbrower他是,用的html标签跟实际web开放中的很类似,只是要遵循winfrom的调用而已。
      

  3.   

    如果webBrowser1 里 是Navigate到一个网站地址,也是可以这样实现的吗?
      

  4.   

    你可以把1楼的webBrowser1.Document.Write里面的HTML放到一个HTML文件里
    然后再用Navigate连接这个页面
      

  5.   

     public Form27()
            {
                InitializeComponent();
                this.webBrowser1.Navigate("http://localhost:9584/");
                this.webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
            }        void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                //throw new NotImplementedException();            System.Windows.Forms.HtmlDocument HTMLDocument = this.webBrowser1.Document;
                System.Windows.Forms.HtmlElement closeBtn = HTMLDocument.GetElementById("ctl00$MainContent$btnClick"); //html中元素标签
                closeBtn.MouseDown += new HtmlElementEventHandler(closeWindw);// // HTML点击按钮
            }        void closeWindw(object o, EventArgs  e)
            {
                this.WindowState = FormWindowState.Minimized;
            }
      

  6.   

    http://blog.csdn.net/zzzzzzzert/article/details/7787481