private void FindKanColleBrowser() { // 強引! var host = Application.Current.MainWindow?.FindName("kanColleHost"); this.kanColleBrowser = host?.GetType().GetProperty("WebBrowser")?.GetValue(host) as WebBrowser; }
public static void SetZoom(this System.Windows.Controls.WebBrowser wb, int zoom) { try { FieldInfo webBrowserInfo = wb.GetType().GetField("_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic); object comWebBrowser = null; object zoomPercent = zoom; if (webBrowserInfo != null) { comWebBrowser = webBrowserInfo.GetValue(wb); } if (comWebBrowser != null) { InternetExplorer ie = (InternetExplorer)comWebBrowser; ie.ExecWB(OLECMDID.OLECMDID_OPTICAL_ZOOM, OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, ref zoomPercent, IntPtr.Zero); if (wb.Document is mshtml.HTMLDocument htmlDoc) { htmlDoc.parentWindow.scrollTo(0, 0); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
protected override void OnClosed(EventArgs e) { base.OnClosed(e); _browser.Dispose(); _browser = null; _events.FireClosed(); }
/// <summary> /// This function is used to zoom web browser's content. /// </summary> /// <param name="webbrowser">The instance of web browser.</param> /// <param name="zoom">The zoom scale. It should be 50~400</param> /// <remarks>This function must be invoked after the webbrowser has completely loaded the URI.</remarks> static void SetZoom(System.Windows.Controls.WebBrowser webbrowser, int zoom) { try { if (null == webbrowser) { return; } FieldInfo fiComWebBrowser = webbrowser.GetType().GetField( "_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic); if (null != fiComWebBrowser) { Object objComWebBrowser = fiComWebBrowser.GetValue(webbrowser); if (null != objComWebBrowser) { object[] args = new object[] { OLECMDID_OPTICAL_ZOOM, OLECMDEXECOPT_DODEFAULT, zoom, IntPtr.Zero }; objComWebBrowser.GetType().InvokeMember( "ExecWB", BindingFlags.InvokeMethod, null, objComWebBrowser, args); } } } catch {} }
/** * Writes the text provided to the output window. The text * will be appended below any existing text already in the * window. */ private void WriteOutputText(string prefix, string outputText, WebBrowser activeBrowser) { try { this.UIThreadInvoke(delegate { if (activeBrowser == null) { activeBrowser = _defaulBrowser; } if (activeBrowser.Tag == null) { activeBrowser.Tag = ""; } var s = activeBrowser.Tag as string; string bodyText = s + string.Format(LINE_TEMPLATE, prefix, DateTime.Now, outputText); activeBrowser.Tag = bodyText; activeBrowser.NavigateToString(string.Format(TEMPLATE, bodyText)); }); } catch (Exception e) { Console.Write(e.Message); } }
public WebBrowserHelper(System.Windows.Controls.WebBrowser webBrowser) { if (webBrowser == null) throw new ArgumentNullException("webBrowser"); _webBrowser = webBrowser; _webBrowser.Dispatcher.BeginInvoke(new Action(Attach), DispatcherPriority.Loaded); }
internal void RetornoXml(WebBrowser webBrowser, string retornoXmlString) { var stw = new StreamWriter(_path + @"\tmp.xml"); stw.WriteLine(retornoXmlString); stw.Close(); webBrowser.Navigate(_path + @"\tmp.xml"); }
private void ClearOutputBrowser(WebBrowser browser) { if (browser != null) { browser.NavigateToString(string.Format(TEMPLATE, "")); browser.Tag = ""; } }
private void ClearBrowsers() { foreach (TabPage tabPage in tabControl.TabPages) { WebBrowser browser = GetActiveBrowser(tabPage.Text); ClearOutputBrowser(browser); } }
public static void ForwardPropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { System.Windows.Controls.WebBrowser browser = o as System.Windows.Controls.WebBrowser; if (null != browser && browser.CanGoForward) { browser.GoForward(); } }
private void InitBrowser() { Control = new WebBrowser(); Control.HorizontalAlignment = HorizontalAlignment.Stretch; Control.LoadCompleted += (s, e) => { Zoom(_zoomFactor); _htmlDocument = (HTMLDocument)Control.Document; _cachedHeight = _htmlDocument.body.offsetHeight; _htmlDocument.documentElement.setAttribute("scrollTop", _positionPercentage * _cachedHeight / 100); foreach (IHTMLElement link in _htmlDocument.links) { HTMLAnchorElement anchor = link as HTMLAnchorElement; if (anchor == null || anchor.protocol != "file:") { continue; } HTMLAnchorEvents_Event handler = anchor as HTMLAnchorEvents_Event; if (handler == null) { continue; } string file = anchor.pathname.TrimStart('/').Replace('/', Path.DirectorySeparatorChar); if (!File.Exists(file)) { anchor.title = "The file does not exist"; return; } handler.onclick += () => { ProjectHelpers.OpenFileInPreviewTab(file); return(true); }; } }; // Open external links in default browser Control.Navigating += (s, e) => { if (e.Uri == null) { return; } e.Cancel = true; if (e.Uri.IsAbsoluteUri && e.Uri.Scheme.StartsWith("http")) { Process.Start(e.Uri.ToString()); } }; }
public JsScriptInserter(WebBrowser webBrowser) { if (webBrowser == null) { throw new ArgumentNullException(nameof(webBrowser)); } _webBrowser = webBrowser; }
private void ScrollChatDown(WebBrowser webBrowserArea) { var html = webBrowserArea.Document as HTMLDocument; if (html != null) { html.parentWindow.scroll(0, 1000000000); } }
/** * Default constructor for an ATMLOutputWindow object */ public ATMLOutputWindow() { InitializeComponent(); LogManager.Instance.OnTrace += AtmlOutputWindowOnTrace; LogManager.Instance.OnError += ATMLOutputWindow_OnError; LogManager.Instance.OnInfo += ATMLOutputWindow_OnInfo; LogManager.Instance.OnWarn += ATMLOutputWindow_OnWarn; elementHost1.Child = _defaulBrowser = new WebBrowser(); }
public MainWindow() { InitializeComponent(); System.Windows.Controls.WebBrowser browser = new System.Windows.Controls.WebBrowser(); // you can put any other uri here, or better make browser field and navigate to desired uri on some event browser.Navigate(new Uri("http://www.blic.rs/")); grdBrowserHost.Children.Add(browser); }
/** * Default constructor for an ATMLOutputWindow object */ public ATMLOutputWindow() { InitializeComponent(); LogManager.Instance.OnTrace += AtmlOutputWindowOnTrace; LogManager.Instance.OnError += ATMLOutputWindow_OnError; LogManager.Instance.OnInfo += ATMLOutputWindow_OnInfo; LogManager.Instance.OnWarn += ATMLOutputWindow_OnWarn; elementHost1.Child = _defaulBrowser = new WebBrowser(); }
/** * Called when the output window encounters a find event. */ private void btnFind_Click(object sender, EventArgs e) { WebBrowser webBrowser = GetActiveBrowser(); if (webBrowser != null) { webBrowser.Focus(); SendKeys.Send("^f"); } }
public void Initialize() { if (IsReady()) { throw new InvalidOperationException(); } this.Show(); _browser = new System.Windows.Controls.WebBrowser(); this.Content = _browser; }
private static void ChangeHtml(WebBrowser webBrowser, IList <IList <IDictionary <string, object> > > items) { var htmlBuilder = new StringBuilder(); using var stringWriter = new StringWriter(htmlBuilder); var xhtmlDumpHelper = new XhtmlDumpHelper(stringWriter); xhtmlDumpHelper.WriteBody(items); webBrowser.NavigateToString(htmlBuilder.ToString()); }
/// <summary> /// Applying CSS styles on document diaplayed in WebBrowser /// </summary> /// <param name="browser">Current WebBrowser</param> /// <param name="style">String containing CSS styles</param> public static void ConfigureBrowser(this System.Windows.Controls.WebBrowser browser, string style) { if (string.IsNullOrEmpty(style)) { return; } if (browser.Document is HTMLDocument document) { IHTMLStyleSheet styleSheet = document.createStyleSheet("", 0); styleSheet.cssText = style; } }
static void _webBrowser_SetDpi(object sender, System.Windows.Navigation.NavigationEventArgs e) { System.Windows.Controls.WebBrowser browser = sender as System.Windows.Controls.WebBrowser; if (null != browser) { browser.LoadCompleted -= new System.Windows.Navigation.LoadCompletedEventHandler(_webBrowser_SetDpi); System.Drawing.PointF scaleUI = GetCurrentDIPScale(); if (100 != (int)(scaleUI.X * 100)) { SetZoom(browser, (int)(scaleUI.X * scaleUI.Y * 100)); } } }
private void abrir_Click(object sender, RoutedEventArgs e) { this.webBrowser.Dispose(); System.Windows.Controls.WebBrowser wb = new System.Windows.Controls.WebBrowser(); wb.Margin = new Thickness(122, 38, 30, 10); wb.Source = new Uri(txtUrl.Text); //https://vivr.io/qz37X91 wb.Visibility = Visibility.Visible; this.webBrowser = wb; this.webBrowser.LoadCompleted += new LoadCompletedEventHandler(browser_LoadCompleted); JacadaGrid.Children.Add(wb); }
private void btnPrint_Click(object sender, EventArgs e) { WebBrowser browser = GetActiveBrowser(); if (browser != null) { var doc = browser.Document as IHTMLDocument2; if (doc != null) { doc.execCommand("Print", true, null); } } }
private void UpdateLink() { System.Windows.Controls.WebBrowser _webBrowser = new System.Windows.Controls.WebBrowser(); _webBrowser.Navigated += _webBrowser_Navigated; if (Uri.IsWellFormedUriString(wnd.siteTB.Text, UriKind.Absolute)) { _webBrowser.Navigate(wnd.siteTB.Text); wnd.updateLinkBT.Content = "Updating..."; } else { wnd.updateLinkBT.Content = "Invalid Link"; } }
public WebBrowserHelper(System.Windows.Controls.WebBrowser webBrowser) { if (webBrowser == null) { throw new ArgumentNullException("webBrowser"); } _webBrowser = webBrowser; _webBrowser.Dispatcher.BeginInvoke(new Action(Attach), DispatcherPriority.Loaded); _webBrowser.Navigated += new System.Windows.Navigation.NavigatedEventHandler(_webBrowser_Navigated); if (NeedZoom()) { _webBrowser.Navigated += new System.Windows.Navigation.NavigatedEventHandler(_webBrowser_SetDpi); } }
//} /// <summary> /// 设置浏览器静默,不弹错误提示框 /// </summary> /// <param name="webBrowser">要设置的WebBrowser控件浏览器</param> /// <param name="silent">是否静默</param> public static void SetWebBrowserSilent(System.Windows.Controls.WebBrowser webBrowser, bool silent) { webBrowser.Navigating += (p1, p2) => { FieldInfo fi = typeof(System.Windows.Controls.WebBrowser).GetField("_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic); if (fi != null) { object browser = fi.GetValue(webBrowser); if (browser != null) { browser.GetType().InvokeMember("Silent", BindingFlags.SetProperty, null, browser, new object[] { silent }); } } }; }
private WebBrowser GetActiveBrowser(object source) { WebBrowser activeBrowser = null; this.UIThreadInvoke(delegate { activeBrowser = elementHost1.Child as WebBrowser; var tab = source as string; if (string.IsNullOrEmpty(tab)) { tabControl.SelectTab(tabControl.TabPages[0]); } else { TabPage selectedPage = null; foreach (TabPage tabPage in tabControl.TabPages) { if (tabPage.Text.Equals(tab)) { selectedPage = tabPage; break; } } if (selectedPage == null) { selectedPage = new TabPage(tab); tabControl.TabPages.Add(selectedPage); var output = new WebBrowser(); var elementHost = new ElementHost(); elementHost.Dock = DockStyle.Fill; elementHost.Location = new Point(3, 3); elementHost.MinimumSize = new Size(20, 20); elementHost.Name = "output" + tabControl.TabPages.Count; elementHost.Size = new Size(704, 155); elementHost.TabIndex = 1; elementHost.Child = output; selectedPage.Controls.Add(elementHost); } tabControl.SelectTab(selectedPage); var host = selectedPage.Controls[0] as ElementHost; if (host != null) { activeBrowser = host.Child as WebBrowser; } } }); return(activeBrowser); }
public WebBrowserHostUIHandler(WebBrowser browser) { if (browser == null) { throw new ArgumentNullException("browser"); } Browser = browser; browser.LoadCompleted += OnLoadCompleted; browser.Navigated += OnNavigated; IsWebBrowserContextMenuEnabled = false; ScriptErrorsSuppressed = true; Flags |= HostUIFlags.DPI_AWARE | HostUIFlags.ENABLE_REDIRECT_NOTIFICATION | HostUIFlags.FLAT_SCROLLBAR | HostUIFlags.DISABLE_SCRIPT_INACTIVE; }
private void InitBrowser() { Control = new WebBrowser { HorizontalAlignment = HorizontalAlignment.Stretch }; Control.LoadCompleted += (s, e) => { _browserWindow.Init();; _htmlDocument = (HTMLDocument)Control.Document; _scrollTracker = new ScrollTracker(_htmlDocument, _services.GetService <IIdleTimeService>()); _scrollTracker.ViewportChange += OnViewportChange; _documentRenderer.RenderCodeBlocks(_htmlDocument); }; // Open external links in default browser Control.Navigating += OnNavigating; }
public void HideScriptErrors(System.Windows.Controls.WebBrowser wb, bool hide) { var fiComWebBrowser = typeof(System.Windows.Controls.WebBrowser).GetField("_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic); if (fiComWebBrowser == null) { return; } var objComWebBrowser = fiComWebBrowser.GetValue(wb); if (objComWebBrowser == null) { wb.Loaded += (o, s) => HideScriptErrors(wb, hide); return; } objComWebBrowser.GetType().InvokeMember("Silent", BindingFlags.SetProperty, null, objComWebBrowser, new object[] { hide }); }
public static void SetSilent(WebBrowser browser, bool silent) { Native.IOleServiceProvider sp = browser.Document as Native.IOleServiceProvider; if (sp != null) { Guid IID_IWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046"); Guid IID_IWebBrowser2 = new Guid("D30C1661-CDAF-11d0-8A3E-00C04FC9E26E"); object webBrowser; sp.QueryService(ref IID_IWebBrowserApp, ref IID_IWebBrowser2, out webBrowser); if (webBrowser != null) { webBrowser.GetType() .InvokeMember("Silent", BindingFlags.Instance | BindingFlags.Public | BindingFlags.PutDispProperty, null, webBrowser, new object[] { silent }); } } }
private WebBrowser GetActiveBrowser() { WebBrowser activeBrowser = null; TabPage selectedPage = tabControl.SelectedTab; if (selectedPage != null) { if (selectedPage.Controls.Count > 0) { activeBrowser = _defaulBrowser; var host = selectedPage.Controls[0] as ElementHost; if (host != null) { activeBrowser = host.Child as WebBrowser; } } } return(activeBrowser); }
public WebContent(RegionOptions options) : base(options.Width, options.Height, options.Top, options.Left) { this.duration = options.Duration; this.scheduleId = options.scheduleId; this.layoutId = options.layoutId; this.mediaId = options.mediaid; this.type = options.FileType; this.webBrowser = new WebBrowser(); this.webBrowser.Height = options.Height; this.webBrowser.Width = options.Width; this.webBrowser.LoadCompleted += new LoadCompletedEventHandler(this.WebBrowserDocumentCompleted); //if (/*!Settings.Default.powerpointEnabled &&*/ (options.FileType == "Powerpoint")) //{ // this.webBrowser.Source = new Uri("<html><body><h1>Powerpoint not enabled on this display</h1></body></html>"); // Trace.WriteLine(string.Format("[*]ScheduleID:{1},LayoutID:{2},MediaID:{3},Message:{0}", new object[] { "Powerpoint is not enabled on this display", this.scheduleId, this.layoutId, this.mediaId })); //} //else { try { try { this.filePath = Uri.UnescapeDataString(options.Uri); } catch (Exception) { } this.webBrowser.Navigate(Application.StartupPath+"\\"+ this.filePath.Replace("\\\\","\\")); MediaCanvas.Children.Add(webBrowser); } catch (Exception exception) { Trace.WriteLine(string.Format("[*]ScheduleID:{1},LayoutID:{2},MediaID:{3},Message:{0}", new object[] { exception.Message, this.scheduleId, this.layoutId, this.mediaId })); this.webBrowser.NavigateToString("<html><body><h1>Unable to show this web location - invalid address.</h1></body></html>"); Trace.WriteLine(string.Format("[*]ScheduleID:{1},LayoutID:{2},MediaID:{3},Message:{0}", new object[] { "Unable to show the powerpoint, cannot be located", this.scheduleId, this.layoutId, this.mediaId })); } } }
public WebBrowser() { C = new System.Windows.Controls.WebBrowser(); }
internal void SetBrowser(System.Windows.Controls.WebBrowser browser) { _browser = browser; }
public void InjectionJquery (WebBrowser browser) { var doc = (HTMLDocument)this.Browser.Document; var head = doc.getElementsByTagName("head").Cast<HTMLHeadElement>().First(); var script = (IHTMLScriptElement)doc.createElement("script"); script.text = Properties.Resources.Jquery; head.appendChild((IHTMLDOMNode)script); }
private void FindKanColleBrowser() { // 強引! var host = Application.Current.MainWindow?.FindName("kanColleHost"); this.kanColleBrowser = host?.GetType().GetProperty("WebBrowser")?.GetValue(host) as WebBrowser; }
public void GetSession() { if (string.IsNullOrWhiteSpace(Token)) GetToken(); if (string.IsNullOrWhiteSpace(ApiSig)) GetApiSig(); var browser = new System.Windows.Controls.WebBrowser(); browser.Navigate("http://www.last.fm/api/auth/?api_key=" + ApiKey + "&token=" + Token); var logWindow = new LogInWindow(browser); logWindow.ShowDialog(); var Params = new RequestParameters { { "token", Token }, { "api_sig", ApiSig }, { "api_key", ApiKey }}; object lfmSession = new Session { ApiKey = ApiKey, ApiSec = ApiSec, ApiSig = ApiSig, Token = Token, Name = Name, Key = Key }; AutomaticGetObject("auth.getsession", Params, ref lfmSession, "session"); var lastSession = lfmSession as Session; if (lastSession != null) { Key = lastSession.Key; Name = lastSession.Name; } }
public SiteManagerCompletedEventArgs Navigate(Uri url, int wait = 0) { SiteManagerCompletedEventArgs result = new SiteManagerCompletedEventArgs() { ResponseUri = url }; bool done = false; System.Windows.Controls.WebBrowser wb = null; Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, new Action(() => { PutControl(wb = new System.Windows.Controls.WebBrowser()); wb.Navigated += (s, e) => { result.ResponseUri = e.Uri; HideScriptErrors(s as System.Windows.Controls.WebBrowser, true); }; wb.LoadCompleted += (s, e) => { result.ResponseUri = e.Uri; done = true; }; wb.Navigate(url); })); #region Wait (done and pause) or 30 sec DateTime endTime = DateTime.Now.AddSeconds(30); while (!done && (DateTime.Now < endTime)) Thread.Sleep(100); if (done) Wait(wait); #endregion Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { try { mshtml.HTMLDocument doc = wb.Document as mshtml.HTMLDocument; if (doc != null && doc.documentElement != null) result.Content = doc.documentElement.innerHTML; } catch (Exception ex) { Helpers.Old.Log.Add(ex, "SiteManagerIE.Navigate().GetHTML()"); } finally { RemoveControl(wb); wb = null; GC.Collect(); } })); return result; }
private void ClearOutputBrowser( WebBrowser browser ) { if (browser != null) { browser.NavigateToString( string.Format( TEMPLATE, "" ) ); browser.Tag = ""; } }
private WebBrowser GetActiveBrowser( object source ) { WebBrowser activeBrowser = null; this.UIThreadInvoke( delegate { activeBrowser = elementHost1.Child as WebBrowser; var tab = source as string; if (string.IsNullOrEmpty( tab )) { tabControl.SelectTab( tabControl.TabPages[0] ); } else { TabPage selectedPage = null; foreach (TabPage tabPage in tabControl.TabPages) { if (tabPage.Text.Equals( tab )) { selectedPage = tabPage; break; } } if (selectedPage == null) { selectedPage = new TabPage( tab ); tabControl.TabPages.Add( selectedPage ); var output = new WebBrowser(); var elementHost = new ElementHost(); elementHost.Dock = DockStyle.Fill; elementHost.Location = new Point( 3, 3 ); elementHost.MinimumSize = new Size( 20, 20 ); elementHost.Name = "output" + tabControl.TabPages.Count; elementHost.Size = new Size( 704, 155 ); elementHost.TabIndex = 1; elementHost.Child = output; selectedPage.Controls.Add( elementHost ); } tabControl.SelectTab( selectedPage ); var host = selectedPage.Controls[0] as ElementHost; if (host != null) activeBrowser = host.Child as WebBrowser; } } ); return activeBrowser; }
/** * Writes the text provided to the output window. The text * will be appended below any existing text already in the * window. */ private void WriteOutputText( string prefix, string outputText, WebBrowser activeBrowser ) { try { this.UIThreadInvoke( delegate { if (activeBrowser == null) activeBrowser = _defaulBrowser; if (activeBrowser.Tag == null) activeBrowser.Tag = ""; var s = activeBrowser.Tag as string; string bodyText = s + string.Format( LINE_TEMPLATE, prefix, DateTime.Now, outputText ); activeBrowser.Tag = bodyText; activeBrowser.NavigateToString( string.Format( TEMPLATE, bodyText ) ); } ); } catch (Exception e) { Console.Write( e.Message ); } }
public ScriptHelper (WebBrowser browser) { mBrowser = browser; }
private void InitBrowser() { Control = new WebBrowser(); Control.HorizontalAlignment = HorizontalAlignment.Stretch; Control.LoadCompleted += (s, e) => { Zoom(_zoomFactor); _htmlDocument = (HTMLDocument)Control.Document; _cachedHeight = _htmlDocument.body.offsetHeight; _htmlDocument.documentElement.setAttribute("scrollTop", _positionPercentage * _cachedHeight / 100); foreach (IHTMLElement link in _htmlDocument.links) { HTMLAnchorElement anchor = link as HTMLAnchorElement; if (anchor == null || anchor.protocol != "file:") continue; HTMLAnchorEvents_Event handler = anchor as HTMLAnchorEvents_Event; if (handler == null) continue; string file = anchor.pathname.TrimStart('/').Replace('/', Path.DirectorySeparatorChar); if (!File.Exists(file)) { anchor.title = "The file does not exist"; return; } handler.onclick += () => { ProjectHelpers.OpenFileInPreviewTab(file); return true; }; } }; // Open external links in default browser Control.Navigating += (s, e) => { if (e.Uri == null) return; e.Cancel = true; if (e.Uri.IsAbsoluteUri && e.Uri.Scheme.StartsWith("http")) Process.Start(e.Uri.ToString()); }; }