Note that there are some explanatory texts on larger screens.

plurals
  1. POWebBrowser Control - Console Application - Events Not Firing
    primarykey
    data
    text
    <p>I have been navigating the various <a href="https://stackoverflow.com/search?q=WebBrowser+control">WebBrowser control stackoverflow questions</a>, and I can't seem to find an answer to a problem I am having. I am trying to use the <a href="https://stackoverflow.com/questions/610183/printing-webbrowser-control-content">WebBrowser control to print a web page</a>. Following <a href="http://msdn.microsoft.com/en-us/library/b0wes9a3.aspx" rel="nofollow noreferrer">MSDN's example</a>, I have created the following console application:</p> <pre><code>namespace WebPrintingMadness { using System; using System.Collections.Generic; using System.Text; /// &lt;summary&gt; /// The entry point of the program. /// &lt;/summary&gt; class Program { /// &lt;summary&gt; /// The main entry point of the program. /// &lt;/summary&gt; /// &lt;param name="args"&gt;Program arguments.&lt;/param&gt; [STAThread] public static void Main(string[] args) { string url = "https://stackoverflow.com/"; WebPagePrinter webPagePrinter = new WebPagePrinter(); webPagePrinter.PrintWebPage(url); Console.ReadLine(); } } } namespace WebPrintingMadness { using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; /// &lt;summary&gt; /// This class is used to print a web page. /// &lt;/summary&gt; internal class WebPagePrinter : IDisposable { /// &lt;summary&gt; /// A System.Windows.Forms.WebBrowser control. /// &lt;/summary&gt; private WebBrowser webBrowser; /// &lt;summary&gt; /// Initializes a new instance of the WebPagePrinter class. /// &lt;/summary&gt; internal WebPagePrinter() { this.webBrowser = new WebBrowser(); this.webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(this.WebBrowser_DocumentCompleted); this.webBrowser.ScriptErrorsSuppressed = true; } /// &lt;summary&gt; /// Disposes of this instance. /// &lt;/summary&gt; public void Dispose() { this.Dispose(true); GC.SuppressFinalize(this); } /// &lt;summary&gt; /// Prints a web page. /// &lt;/summary&gt; /// &lt;param name="url"&gt;The url of the web page.&lt;/param&gt; internal void PrintWebPage(string url) { this.webBrowser.Navigate(url); } /// &lt;summary&gt; /// Disposes of this instance. /// &lt;/summary&gt; /// &lt;param name="disposing"&gt;True if disposing, otherwise false.&lt;/param&gt; protected virtual void Dispose(bool disposing) { if (disposing) { if (this.webBrowser != null) { this.webBrowser.Dispose(); this.webBrowser = null; } } } /// &lt;summary&gt; /// Event handler for the webBrowser DocumentCompleted event. /// &lt;/summary&gt; /// &lt;param name="sender"&gt;The event sender.&lt;/param&gt; /// &lt;param name="e"&gt;The event arguments.&lt;/param&gt; private void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { WebBrowser navigated = sender as WebBrowser; if (navigated == null) { return; } navigated.Print(); navigated.Dispose(); } } } </code></pre> <p>However, the DocumentCompleted event never fires. Is it possible to use this Windows.Forms control in an console application?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload