using CefSharp; using CefSharp.WinForms; using efunbox_xyyf_windows.baseMvp; using efunbox_xyyf_windows.bean; using efunbox_xyyf_windows.contract; using efunbox_xyyf_windows.cusview; using efunbox_xyyf_windows.presenter; using efunbox_xyyf_windows.util; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace efunbox_xyyf_windows { public delegate void ChangeWebUrl(string url); public delegate void WebViewReload(); public delegate string getWebUrl(); public partial class Main : BaseForm, MainContract.IView { /* * debug使用到的方法 * **/ public static ChangeWebUrl changeWebUrl; public static WebViewReload webviewReload; public static getWebUrl getWebNowUrl; //webview ChromiumWebBrowser webview; public Main() { InitializeComponent(); this.FormClosing += Form1_FormClosing; } //窗体加载 private void Form1_Load(object sender, EventArgs e) { mPresenter = new MainPresenter(); mPresenter.attachView(this); changeWebUrl = ChangeWebUrl; webviewReload = WebViewReload; getWebNowUrl = getWebUrl; } //窗体第一次显示 private void Form1_Shown(object sender, EventArgs e) { loadingProgress.Value = 20; mPresenter.LenvAutoLogin(); } /* * 窗体关闭 * **/ private void Form1_FormClosing(Object sender, FormClosingEventArgs e) { //阻止关闭 //e.Cancel = true; //调用js方法通知网页用户想关闭应用 //webview.GetBrowser().MainFrame.EvaluateScriptAsync("FormClosing()"); //JS会回调JsInterface里面的exitApp()方法进行退出 Cef.Shutdown(); if (webview != null) { webview.Dispose(); } } public string getWebUrl() { return mPresenter.getWebUrl(); } public ChromiumWebBrowser getWebView() { try { return webview; } catch (Exception ex) { Console.WriteLine(ex.Message); return null; } } public void getLenvIdSuccess() { loadingProgress.Value = 100; loadingProgress.Visible = false; //都获取到信息了,初始化webview webview = new ChromiumWebBrowser(); mPresenter.initWebView(webview); this.Controls.Add(webview); showDialog(); } public ProgressBar getLoadingBar() { return loadingProgress; } /* * * 以下是测试方法,DebugUtilForm窗口调用 * * **/ public void showDialog() { //测试用 DialogResult MsgBoxResult;//设置对话框的返回值 MsgBoxResult = System.Windows.Forms.MessageBox.Show("打开debug操作窗?", " ", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);//定义对话框的按钮式样 if (MsgBoxResult.ToString() == "Yes")//如果对话框的返回值是YES(按"Y"按钮) { DebugUtilForm debugUtilForm = new DebugUtilForm(); debugUtilForm.Show(this); } if (MsgBoxResult.ToString() == "No")//如果对话框的返回值是NO(按"N"按钮) { //选择了No,继续 } } public void ChangeWebUrl(string url) { webview.LoadUrl(url); } public void WebViewReload() { webview.Reload(); } } }