日期:2014-05-18  浏览次数:20923 次

aspx页面的关闭按钮如何 关闭 winform 窗口程序


使用winform 的 webBrowser 控件 把页面嵌入到winform窗口里  

aspx页面有关闭按钮 点击 关闭按钮 关闭 winform程序 

请教各位 该如何实现该功能呢?

------解决方案--------------------
C# code

        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();
        }

------解决方案--------------------
探讨


------解决方案--------------------
<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();
}
}
}

------解决方案--------------------

js中调用C#代码:
C# code

public void close()
  {
  this.close();
  }