using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using Lskj.Util; using Gecko; using Gecko.Events; using Lskj.Business.Impl; using System.Runtime.InteropServices; namespace Lskj.Control { public partial class ModuleWebView : UserControl { public ModuleWebView() { InitializeComponent(); Gecko.LauncherDialog.Download -= new EventHandler(LauncherDialog_Download); } GeckoWebBrowser browser; WebBrowser browserNew; public static bool Evenflag; public EventHandler OnNavigating; /// /// 说明:打开网页 /// 创建人:龚宇超 /// 创建日期:2019-03-14 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// public void Navigate(string url) { Navigate(url, GeckoLoadFlags.None); } public void Navigate(string url, GeckoLoadFlags flag) { try { if (Directory.Exists(PubUtil.WebViewPath) && File.Exists(Path.Combine(PubUtil.WebViewPath, "crashreporter.exe"))) { url = url + "&t=" + DateTime.Now.Ticks; if (browser != null) { browser.Dispose(); browser = null; } Xpcom.Initialize(PubUtil.WebViewPath); browser = new GeckoWebBrowser(); browser.Dock = DockStyle.Fill; browser.Name = "browser"; browser.NoDefaultContextMenu = true; //禁用右键菜单 if (OnNavigating != null) { browser.Navigating += OnNavigating; } this.panelControl1.Controls.Add(browser); if (!Evenflag) { Gecko.LauncherDialog.Download += new EventHandler(LauncherDialog_Download); Evenflag = true; } browser.Navigate(url, flag); } else { MessageUtil.Show("未找到浏览器资源文件,请联系开发人员."); } } catch (Exception ex) { MessageUtil.Show("浏览器出错!" + ex); } } /// /// 触发下载事件 /// /// /// private void LauncherDialog_Download(Object sender, LauncherDialogEvent e) { string tipMsg = string.Empty; DataRow RT = AttachImpl.GetTempletFile(e.Filename); if (AttachImpl.CheckAttachOperation(2, "", Convert.ToInt32(RT["fileId"]), "", 0, out tipMsg) == 1) { if (browserNew != null) { browserNew.Dispose(); browserNew = null; } browserNew = new WebBrowser();//点击下载的页面 this.panelControl1.Controls.Add(browserNew); browserNew.Navigate(e.Url); } else { MessageUtil.Show(tipMsg); } } public void FDispose() { if (browser != null) { browser.Dispose(); } this.Dispose(); } } }