ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

[SOLVED] C# WebBrowser Event not firing!

(1/1)

Asudem:
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# ---public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }         private void button1_Click(object sender, EventArgs e)        {            Form2 form2 = new Form2();            form2.Show();        }                private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)        {            MessageBox.Show(webBrowser1.Url.ToString());        }         private void Form1_Load(object sender, EventArgs e)        {            webBrowser1.Navigate("http://www.google.com");            webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;        }    }
--- Code: C# ---public partial class Form2 : Form    {        public Form2()        {            InitializeComponent();        }         private void button1_Click(object sender, EventArgs e)        {            Form1 form1 = new Form1();            form1.Show();        }    }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]

Navigation

[0] Message Index

Go to full version