使用winform 的 webBrowser 控件 把页面嵌入到winform窗口里  aspx页面有关闭按钮  点击 关闭按钮  关闭 winform程序 请教各位  该如何实现该功能呢?

解决方案 »

  1.   


            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 list1 = HTMLDocument.GetElementById("ctl00$MainContent$btnClick");
                list1.MouseDown += new HtmlElementEventHandler(closeWindw);// // 指定监视
            }        void closeWindw(object o, EventArgs  e)
            {
                this.Close();
            }
      

  2.   

    可以使用js关闭本页面。
    windows.close();
      

  3.   

    <script type="text/javascript">
        btnClose.onmousedown = function() {
            window.external.close();
        }
    </script>
    namespace CLose
    {
        [System.Runtime.InteropServices.ComVisibleAttribute(true)]
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                webBrowser1.ObjectForScripting = this;//允许脚本调用
                webBrowser1.Url = new Uri(@"E:\project\WebBrowse\CLose\close.htm");
            }
            private void close()
            {
                this.close();
            }
        }
    }
      

  4.   


    js中调用C#代码:public void close()
      {
      this.close();
      }
    function close()
    {
    window.external.close();
    }