private static void Refresh(WbRefreshThread refresher, Proxy proxy) { WebBrowserEx wbWebBrowser = new WebBrowserEx(); wbWebBrowser.ScriptErrorsSuppressed = true; if (refresher.useProxy) { wbWebBrowser.ProxyServer = proxy.IpAndPort; } else { wbWebBrowser.ProxyServer = ""; } wbWebBrowser.Navigate(refresher.Url); Stopwatch sw = new Stopwatch(); sw.Start(); while (wbWebBrowser.ReadyState < WebBrowserReadyState.Complete) { Application.DoEvents(); if (sw.ElapsedMilliseconds > refresher.timeOut * 1000) { throw new WebException(WebExceptionStatus.Timeout.ToString()); } } sw.Stop(); refresher.SuccessCount++; refresher.Description = wbWebBrowser.ProxyServer + "刷新成功!"; }
private void InitHtmlRender(out WebBrowserEx browser) { browser = new WebBrowserEx() { DocumentText = string.Empty.GetHtmlFromTemplate(), Dock = System.Windows.Forms.DockStyle.Fill, ScriptErrorsSuppressed = true, IgnoreAllError = true, WebBrowserShortcutsEnabled = false, AllowNavigation = true, AllowWebBrowserDrop = false }; browser.Navigate("about:blank"); browser.Document.Write(string.Empty); try { if (browser is System.Windows.Forms.WebBrowser) { browser.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(WebBrowser_DocumentCompleted); browser.Navigating += new System.Windows.Forms.WebBrowserNavigatingEventHandler(WebBrowser_Navigating); browser.ProgressChanged += new System.Windows.Forms.WebBrowserProgressChangedEventHandler(WebBrowser_ProgressChanged); browser.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(WebBrowser_PreviewKeyDown); TrySetSuppressScriptErrors(webHtml, true); } } catch (Exception ex) { ex.ERROR(); } }
private void LoadAllOfflineProduct() { allProductList.Clear(); this.listView.Items.Clear(); webBrowser = new WebBrowserEx(); webBrowser.Navigate(URL); webBrowser.DocumentCompleted += webBrowser_DocumentCompleted; }
void LoadAllPagesBtnClick(object sender, EventArgs e) { wb2.Navigate("https://somehueinstance.com/impala"); wb3.Navigate("https://somehueinstance.com/impala"); wb4.Navigate("https://somehueinstance.com/impala"); wb5.Navigate("https://somehueinstance.com/impala"); wb6.Navigate("https://somehueinstance.com/impala"); wb7.Navigate("https://somehueinstance.com/impala"); wb8.Navigate("https://somehueinstance.com/impala"); wb9.Navigate("https://somehueinstance.com/impala"); wb10.Navigate("https://somehueinstance.com/impala"); }
private void RenderImage(string url) { try { using (WebBrowserEx wb = new WebBrowserEx()) { wb.DocumentCompleted += Browser_DocumentCompletedSingle; wb.ProgressChanged += Wb_ProgressChanged; wb.ScrollBarsEnabled = false; wb.Navigate(url); wb.Refresh(WebBrowserRefreshOption.Completely); while (wb.IsBusy) { Application.DoEvents(); } for (int i = 0; i < AMOUNTOFITERATIONS; i++) { if (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); Thread.Sleep(SLEEPTIME); } else { break; } } Thread.Sleep(SLEEPTIME * 50); //To make sure websites are properly rendered Application.DoEvents(); endOfRender = true; Browser_DocumentCompletedSingle(wb, new WebBrowserDocumentCompletedEventArgs(wb.Url)); } } catch { if (error == "") { error = "Something went wrong.\r\n\r\nCheck if you have a working internet connection. In case that does not help, restart the application and try again."; } MessageBox.Show(error, APPTITLE, MessageBoxButtons.OK, MessageBoxIcon.Information); error = ""; } }
public static void Main() { var frm = new Form(); frm.Size = new Size(800, 600); var ie = new WebBrowserEx(); ie.ScriptErrorsSuppressed = false; frm.Load += (s, e) => { var path = Path.GetFullPath("index.html"); ie.Navigate(path); }; ie.Dock = DockStyle.Fill; frm.Controls.Add(ie); frm.ShowDialog(); }
/// <summary> /// 初始化浏览器 /// </summary> private void InitializeWebBrowser() { browser = new WebBrowserEx() { Dock = DockStyle.Fill }; this.Controls.Add(browser); BindBrowserContextMenu(); bool isBrowserInited = false; browser.DocumentCompleted += (s, e) => { if (!isBrowserInited && browser.ReadyState == WebBrowserReadyState.Complete) { isBrowserInited = true; foreach (object item in notReadyScriptList) { if (item is string) { SendMessage(item as string); } else if (item is Alias.Message) { DropMessage(item as Alias.Message); } else if (item is object[]) { object[] arr = item as object[]; AddFileToSendList((bool)arr[0], arr[1] as string, (ulong)arr[2]); } else if (item is KeyValuePair <int, FileTaskEventArgs> ) { KeyValuePair <int, FileTaskEventArgs> ea = (KeyValuePair <int, FileTaskEventArgs>)item; switch (ea.Key) { case 0: AddSendTask(ea.Value); break; //0-添加发送任务 case 1: AddReceiveTask(ea.Value); break; //1-添加接收任务 case 2: TaskItemProgressChange(ea.Value); break; //2-任务进度变化 case 3: TaskItemStateChange(ea.Value); break; //3-任务状态变化 case 4: SendTaskFinish(ea.Value); break; //4-发送任务完成 case 5: SendTaskStart(ea.Value); break; //5-发送任务开始 case 6: SendTaskExpires(ea.Value); break; //6-发送任务过期 case 7: ReceiveTaskFinish(ea.Value); break; //7-接收任务完成 case 8: ReceiveTaskStart(ea.Value); break; //8-接收任务开始 } } else if (item is FileSystemOperationErrorEventArgs) { FileOperationError(item as FileSystemOperationErrorEventArgs); } else if (item is FileTaskInfo) { ReceiveFileRequired(item as FileTaskInfo); } } } }; browser.DragFile += (s, e) => Array.ForEach(e.Files, AddFileToSendList); //初始化浏览器 browser.Navigate(String.Format(@"{0}Chat\IEView\main.html", Core.ProfileManager.GetThemeFolder())); browser.ObjectForScripting = this; //浏览器拖放文件 //browser.AllowNavigation = false; //禁止浏览 browser.WebBrowserShortcutsEnabled = false; //禁止快捷键 browser.EnableFileDrag = true; //browser.ScriptErrorsSuppressed = true; //禁止错误? }
private void gWebBrowserContainer_Loaded(object sender, RoutedEventArgs e) { var container = sender as Grid; if (container != null && container.Children.Count == 0) { WindowsFormsHost host = new WindowsFormsHost(); container.Children.Add(host); var model = this.DataContext as SecureBrowserViewModel; WebBrowserEx wb = new WebBrowserEx(model.SelectedTabItem); wb.Navigating += wb_Navigating; wb.Navigated += wb_Navigated; //wb.Validating += wb_Validating; wb.FileDownload += wb_FileDownload; wb.DocumentCompleted += wb_DocumentCompleted; wb.ProgressChanged += wb_ProgressChanged; wb.ScriptErrorsSuppressed = true; //disable popup for javascript errors SHDocVw.WebBrowser axBrowser = (SHDocVw.WebBrowser)wb.ActiveXInstance; axBrowser.NewWindow3 += axBrowser_NewWindow3; //axBrowser.NewWindow2 += axBrowser_NewWindow2; //wb.IsWebBrowserContextMenuEnabled = false; //disable context menu //dynamic d = wb.ActiveXInstance; //string uri = string.Empty; //d.BeforeNavigate2 += new BeforeNavigate2((object pDisp, // ref dynamic url, // ref dynamic Flags, // ref dynamic TargetFrameName, // ref dynamic PostData, // ref dynamic Headers, // ref bool Cancel) => // { // uri = url.ToString(); // Trace.WriteLine(uri); // }); //d.FileDownload += new FileDownload((bool bActiveDocument, ref bool bCancel) => //{ // bool isFile = uri.EndsWith("exe"); // if (isFile) // { // bCancel = true; // Trace.Write("Canceled a file download from the DLR."); // } //}); host.Child = wb; if (model != null && model.SelectedTabItem != null) { model.SelectedTabItem.SearchBar.OnNavigateRequired += SearchBar_OnNavigateRequired; model.SelectedTabItem.WebBrowser = wb; if (!string.IsNullOrWhiteSpace(model.SelectedTabItem.SearchBar.Address)) { wb.Navigate(model.SelectedTabItem.SearchBar.Address); } } } }
public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); // // TODO: Add constructor code after the InitializeComponent() call. // wb1.Dock = DockStyle.Fill; tabPage1.Controls.Add(wb1); wb1.Id = "1"; wb2.Dock = DockStyle.Fill; tabPage2.Controls.Add(wb2); wb2.Id = "2"; wb3.Dock = DockStyle.Fill; tabPage3.Controls.Add(wb3); wb3.Id = "3"; wb4.Dock = DockStyle.Fill; tabPage4.Controls.Add(wb4); wb4.Id = "4"; wb5.Dock = DockStyle.Fill; tabPage5.Controls.Add(wb5); wb5.Id = "5"; wb6.Dock = DockStyle.Fill; tabPage6.Controls.Add(wb6); wb6.Id = "6"; wb7.Dock = DockStyle.Fill; tabPage7.Controls.Add(wb7); wb7.Id = "7"; wb8.Dock = DockStyle.Fill; tabPage8.Controls.Add(wb8); wb8.Id = "8"; wb9.Dock = DockStyle.Fill; tabPage9.Controls.Add(wb9); wb9.Id = "9"; wb10.Dock = DockStyle.Fill; tabPage10.Controls.Add(wb10); wb10.Id = "10"; webList.Add(wb1); webList.Add(wb2); webList.Add(wb3); webList.Add(wb4); webList.Add(wb5); webList.Add(wb6); webList.Add(wb7); webList.Add(wb8); webList.Add(wb9); webList.Add(wb10); wb1.Navigate("https://somehueinstance.com/impala"); }