121 lines
3.8 KiB
C#
121 lines
3.8 KiB
C#
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<LauncherDialogEvent>(LauncherDialog_Download);
|
|
}
|
|
GeckoWebBrowser browser;
|
|
WebBrowser browserNew;
|
|
public static bool Evenflag;
|
|
|
|
public EventHandler<GeckoNavigatingEventArgs> OnNavigating;
|
|
|
|
/// <summary>
|
|
/// <para>说明:打开网页</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2019-03-14 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
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<LauncherDialogEvent>(LauncherDialog_Download);
|
|
Evenflag = true;
|
|
}
|
|
browser.Navigate(url, flag);
|
|
|
|
}
|
|
else
|
|
{
|
|
MessageUtil.Show("未找到浏览器资源文件,请联系开发人员.");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
MessageUtil.Show("浏览器出错!" + ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 触发下载事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
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();
|
|
|
|
}
|
|
}
|
|
}
|