/// <summary> /// Creates the underlying CfxBrowser with the given CfxRequestContext. /// This method should only be called if this ChromiumWebBrowser /// was instanciated with createImmediately == false. /// </summary> public void CreateBrowser(CfxRequestContext requestContext) { // avoid illegal cross-thread calls if (InvokeRequired) { Invoke((MethodInvoker)(() => CreateBrowser(requestContext))); return; } var parentHandle = this.Handle; //var rect = this.ClientRectangle; //if (this.Parent != null) //{ // parentHandle = this.Parent.Handle; // rect = this.Parent.ClientRectangle; //} var windowInfo = new CfxWindowInfo(); //this.ImeMode = ImeMode.Inherit; //if (WindowLess) { // // in order to avoid focus issues when creating browsers offscreen, // // the browser must be created with a disabled child window. // windowInfo.SetAsDisabledChild(parentHandle); // //windowInfo.SetAsChild (); //} else { //windowInfo.SetAsChild(parentHandle, rect.Left, rect.Top, rect.Width, rect.Height); //windowInfo.SetAsDisabledChild(parentHandle); // //windowInfo.Style = WindowStyle.WS_CHILD; //} // this work in windows. windowInfo.SetAsDisabledChild(parentHandle); if (!CfxBrowserHost.CreateBrowser(windowInfo, client, initialUrl, DefaultBrowserSettings, requestContext)) { throw new ChromiumWebBrowserException("Failed to create browser instance."); } }
/// <summary> /// 创建一个浏览器窗口 /// </summary> /// <param name="formHandle">当前承载浏览器窗口的 Form 窗体的句柄号(Handle)</param> /// <param name="defWidth">默认宽度</param> /// <param name="defHeight">默认高度</param> /// <param name="initialUrl">初始的超链接,默认为空白页</param> /// <returns></returns> public IWebBrowserWindow CreateBrowser(IntPtr formHandle, int defWidth, int defHeight, string initialUrl = "about:blank") { if (!Bootstrapper.Current.IsStarted) { Bootstrapper.Current.Start(); } var browserWindow = new WebBrowserWindow(defWidth, defHeight); var windowInfo = new CfxWindowInfo(); windowInfo.SetAsDisabledChild(formHandle); var browserSettings = new CfxBrowserSettings(); if (!CfxBrowserHost.CreateBrowser(windowInfo, browserWindow._browserClient, initialUrl, browserSettings, null)) { throw new WebEngineException("对不起!浏览器窗口创建失败,请确认所有配置正确后重试。"); } _browsers.Add(new WebBrowserReference(browserWindow)); return(browserWindow); }