> I am using the webbrowser control in a winforms app. It is an unattended
> app, so as soon as the event "form1_shown" is fired the webbrowser control
[quoted text clipped - 30 lines]
> }
> }
Where should I place the Application.Exit?
The current order of events are as follows:
1. the form loads using InitializeComponent (only two controls are loaded, a
button and the webbrowser control).
2. In the Form1_Shown I click the button
private void Form1_Shown(object sender, EventArgs e)
{
button1.PerformClick();
}
3. The button click event loads a url into the browser control and wires the
print event for document completed.
private void button1_Click(object sender, EventArgs e)
{
try
{
string[] args = Environment.GetCommandLineArgs();
string URL = args[1].Trim();
if (!URL.StartsWith("http://") && !URL.StartsWith("https://"))
{
URL = "http://" + URL;
}
webBrowser1.Navigate(new Uri(URL));
webBrowser1.DocumentCompleted += new
WebBrowserDocumentCompletedEventHandler(PrintDocument);
}
catch (Exception ex)
{
}
}
4. the print event fires, but IMPORTANT: the actual document does not start
printing until all these events are fired???
private void PrintDocument(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
try
{
// Print the document now that it is fully loaded.
((System.Windows.Forms.WebBrowser)sender).Print();
//WebBrowserReadyState state = webBrowser1.ReadyState;
//webBrowser1.ShowPrintDialog();
// Dispose the WebBrowser now that the task is complete.
((System.Windows.Forms.WebBrowser)sender).Dispose();
//System.Windows.Forms.Application.Exit();
}
catch (Exception ex)
{
}
}
5. then the default dispose fires
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
//System.Windows.Forms.Application.Exit();
}
6. The print job now starts? All my code is done executing when this occurs.
As you can see, I've tried calling Application.Exit in both 4 and 5 and they
are both too early. I guess what I am looking for is another event, one in
the winforms that runs after the print job has finished.
I'm sure its an easy solution, I just dont work with winforms often.
Thanks Again
> On 13 mar, 09:20, Chris Fink <ChrisF...@discussions.microsoft.com>
> wrote:
[quoted text clipped - 35 lines]
> You could try placing the Application.Exit() after the webbrowser
> dispose.
ocram83@gmail.com - 14 Mar 2008 18:56 GMT
On 14 mar, 10:26, Chris Fink <ChrisF...@discussions.microsoft.com>
wrote:
> Where should I place the Application.Exit?
>
[quoted text clipped - 119 lines]
>
> - Mostrar texto de la cita -
There's always an easy way. Use a MessageBox to ask the user if the
document is done printing. when the user presses Yes (Ok or whatever)
execute the Application.Exit().
If you want we can keep looking.
ocram83@gmail.com - 14 Mar 2008 19:29 GMT
On 14 mar, 10:56, ocra...@gmail.com wrote:
> On 14 mar, 10:26, Chris Fink <ChrisF...@discussions.microsoft.com>
> wrote:
[quoted text clipped - 130 lines]
>
> - Mostrar texto de la cita -
This is another way:
I've added a just WebBrowser and a Timer to the form. I set the
Interval property of the timer to 2000 (2 secs). My code looks like
this:
private void Form1_Load(object sender, EventArgs e)
{
this.webBrowser1.Navigate("http://www.google.com");
}
private void webBrowser1_DocumentCompleted(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
this.webBrowser1.Print();
this.timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
this.timer1.Stop();
Application.Exit();
}
This does what you want. Hope it can help.
Chris Fink - 17 Mar 2008 14:47 GMT
This works. Thank You for your help. I still wish there was a more eloquent
solution with a Print Finished event, etc. I'll have to set the timer
interval pretty high in order to guarantee the app doesn't exit before the
printing; the higher the timer value the more sluggish the application.
Thanks again
> On 14 mar, 10:56, ocra...@gmail.com wrote:
> > On 14 mar, 10:26, Chris Fink <ChrisF...@discussions.microsoft.com>
[quoted text clipped - 156 lines]
>
> This does what you want. Hope it can help.