using Lskj.MyControl.BrowserSetting; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Net; using System.Text; using System.Windows.Forms; using Xilium.CefGlue; namespace Lskj.MyControl { public partial class FrmWebBrowser : UserControl { public DynamicPubBrowerModel PubBrowerModel; public CefBrowser cefBrowserSettings; public FrmWebBrowser() { InitializeComponent(); } void Form1_FormClosed(object sender, FormClosedEventArgs e) { //CefRuntime.Shutdown(); } public void FrmLoad(string url) { //CefWebBrowser browser = new CefWebBrowser(); //browser.Dock = DockStyle.Fill; //string url1 = "https://ie.icoa.cn/"; //browser.StartUrl = Url; //this.Controls.Add(browser); var cefWindowInfo = CefWindowInfo.Create(); cefWindowInfo.SetAsChild(this.Handle, new CefRectangle(0, 0, this.Width, this.Height)); var bsClient = new BsClient(); bsClient.OnCreated += bsClient_OnCreated; var cefBrowserSettings = new CefBrowserSettings() { }; //Url = "https://ie.icoa.cn/"; CefBrowserHost.CreateBrowser(cefWindowInfo, bsClient, cefBrowserSettings, url); this.SizeChanged += parent_SizeChanged; } private void bsClient_OnCreated(object sender, EventArgs e) { cefBrowserSettings = (CefBrowser)sender; var handle = cefBrowserSettings.GetHost().GetWindowHandle(); ResizeWindow(handle, this.Width, this.Height); } private void parent_SizeChanged(object sender, EventArgs e) { if (cefBrowserSettings != null) { var handle = cefBrowserSettings.GetHost().GetWindowHandle(); ResizeWindow(handle, this.Width, this.Height); } } private void ResizeWindow(IntPtr handle, int width, int height) { if (handle != IntPtr.Zero) { NativeMethod.SetWindowPos(handle, IntPtr.Zero, 0, 0, width, height, 0x0002 | 0x0004 ); } } public void LoadUrl(string url) { cefBrowserSettings.GetMainFrame().LoadUrl(url); } public void LoadRequest(string url, string dataStr) { BrowserSetting.HttpTools.setting("application/x-www-form-urlencoded", null, null); Dictionary dataDic = new Dictionary(); dataDic.Add("billCode", dataStr); HttpWebResponse webResponse = BrowserSetting.HttpTools.Post(url, "", dataDic, HttpTools.Method.POST); if (webResponse != null) { cefBrowserSettings.GetMainFrame().LoadUrl(webResponse.ResponseUri.AbsoluteUri); } } } public class DynamicPubBrowerModel { public int ModuleId; public string FormText; public string Privilege; public string ModuleCode; public string UserId; public string UserName; public bool IsDetailSearch; public string[] Params; /// /// url参数 /// public string UrlParame; public string BetweenDLLCoid; /// /// 是否是右键下载 /// /// public int downLoadFlag; public int RightKeyFlag; public int isView; public int isPostFlag; public string postData; public double PerWidth;//百分比宽 public double PerHeight;//百分比高 public bool isCalSize = false;//是否自定义控件高宽 public DynamicPubBrowerModel(string[] args) { this.FormText = args[0]; this.UserId = args[1]; this.UserName = args[2]; this.Privilege = args[3]; this.ModuleCode = args[4]; this.ModuleId = 0; this.Params = new string[args.Length]; for (int i = 8; i < args.Length; i++) { Params[i - 8] = args[i]; } // 右键菜单打开的模块没有moduleId,部分特殊模块没有moduleId比如添加界面. if (!string.IsNullOrEmpty(args[5])) { this.ModuleId = Convert.ToInt32(args[5]); } if (args.Length > 6 && !string.IsNullOrEmpty(args[6])) { this.UrlParame = args[6]; } if (args.Length > 7) { this.BetweenDLLCoid = args[7]; } if (args.Length > 8 && !string.IsNullOrEmpty(args[8])) { this.downLoadFlag = Convert.ToInt32(args[8]); } if (args.Length > 9 && !string.IsNullOrEmpty(args[9])) { this.RightKeyFlag = Convert.ToInt32(args[9]); } if (args.Length > 10 && !string.IsNullOrEmpty(args[10])) { this.isView = Convert.ToInt32(args[9]); } if (args.Length > 11 && !string.IsNullOrEmpty(args[11])) { this.isPostFlag = 1; this.postData = args[11]; } if (args.Length > 14 && !string.IsNullOrEmpty(args[13]) && !string.IsNullOrEmpty(args[14])) { PerWidth = (int.Parse(args[13].Replace("%", "")) * 0.01); PerHeight = (int.Parse(args[14].Replace("%", "")) * 0.01); isCalSize = true; } } } }