Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 05, 2016, 02:50:52 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: [SOLVED] C# WebBrowser Event not firing!  (Read 479 times)

Asudem

  • Member
  • Joined in 2015
  • **
  • Posts: 100
  • C# data manipulation junkie
    • View Profile
    • Donate to Member
[SOLVED] C# WebBrowser Event not firing!
« on: March 06, 2016, 10:31:06 AM »
Hey kids, it's your uncle Asudem here with some sage like advice.

If you have an event that needs to fire, but also assign that event in the initialization of the form, make sure you have some kind of check to not to add the initialized event the second time around.

Alright guys, I'm at my wit's end.

I have a Winform with a WebBrowser control, and once a page loads, it fires an event. Everything works correctly and as intended.

If I create a new instance of that Winform, then load a page into the WebBrowser on the newly created Winform, the same code which assigns the WebBrowser event does not fire....

For example

Code: C# [Select]
  1. public partial class Form1 : Form
  2.     {
  3.         public Form1()
  4.         {
  5.             InitializeComponent();
  6.         }
  7.  
  8.         private void button1_Click(object sender, EventArgs e)
  9.         {
  10.             Form2 form2 = new Form2();
  11.             form2.Show();
  12.         }
  13.        
  14.         private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
  15.         {
  16.             MessageBox.Show(webBrowser1.Url.ToString());
  17.         }
  18.  
  19.         private void Form1_Load(object sender, EventArgs e)
  20.         {
  21.             webBrowser1.Navigate("http://www.google.com");
  22.             webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
  23.         }
  24.     }
Code: C# [Select]
  1. public partial class Form2 : Form
  2.     {
  3.         public Form2()
  4.         {
  5.             InitializeComponent();
  6.         }
  7.  
  8.         private void button1_Click(object sender, EventArgs e)
  9.         {
  10.             Form1 form1 = new Form1();
  11.             form1.Show();
  12.         }
  13.     }
When Form2 creates a new instance of Form1, there is no messagebox once the navigated url is loaded... I am dumbfounded... Any ideas what might be going wrong?[/s]
If I do it more than 2 times I want to automate it in C#!
« Last Edit: March 06, 2016, 10:57:08 AM by Asudem, Reason: I can\'t brain today. I have the dumb. »