views:

183

answers:

3

How can I properly access the web browser control from within myFunct()? Main.myWebBrowserControl & Main::myWebBrowserControl don't work.

namespace foo{
    public partial class Main : Form{
     public Main(){
      InitializeComponent();
      // Do some things...
      MyFunct();
     }
     public static void MyFunct(){
      myWebBrowserControl.Navigate("http://www.google.com"); // causing an error.
     }
    }
}
A: 

Make MyFunct not be static.

John Saunders
A: 
Michał Piaskowski
+1  A: 

In addition to not being static (as was said above) you also have to ensure that what you're executing is on the "main thread" of the application. This is the same thread that handles events (such as handling a "click event" from the app), and so if you're calling the method from there, then you're fine, but if not, you MUST wrap an Invoke() or BeginInvoke() call around Navigate().

Kevin