M
Matthias Kwiedor
Hi!
I want to create a WebBrowser Control at runtime. So i ported the "at
start creation" of the Control to a new routine.
Everything works fine, but i implement the BeforeNavigateFix and a own
Content Menu. For this i need this lines:
public void create_new_browser()
{
AxSHDocVw.AxWebBrowser AxWebBrowser1 = new AxSHDocVw.AxWebBrowser();
// Here is the code for adding the control to the form
// ...
// ...
object obj = AxWebBrowser1.GetOcx();
IOleObject oc = obj as IOleObject;
oc.SetClientSite(this); // System.NullReferenceException
// Fix for OnBeforeNavigate .Net 1.0
ie_events = (SHDocVw.WebBrowserClass) Marshal.CreateWrapperOfType
(AxWebBrowser1.GetOcx(), typeof(SHDocVw.WebBrowserClass));
SHDocVw.DWebBrowserEvents_BeforeNavigateEventHandler BeforeNavigateE =
new SHDocVw.DWebBrowserEvents_BeforeNavigateEventHandler
(OnBeforeNavigate);
ie_events.BeforeNavigate +=
BeforeNavigateE;//System.NullReferenceException
}
If i Comment the both lines with // System.NullRefernceException it
runs, but with no BeforeNavigate Event, and not with the content menu -
which worked fine before creating it at runtime.
I tried several things, but running out of ideas and found nothing with
google
All it throws out is a System.NullReferenceException and that the object
ist not bound to the instance.
Maybe someone has done this before or can me give some hints.
Thanks for your Help
Matt
I want to create a WebBrowser Control at runtime. So i ported the "at
start creation" of the Control to a new routine.
Everything works fine, but i implement the BeforeNavigateFix and a own
Content Menu. For this i need this lines:
public void create_new_browser()
{
AxSHDocVw.AxWebBrowser AxWebBrowser1 = new AxSHDocVw.AxWebBrowser();
// Here is the code for adding the control to the form
// ...
// ...
object obj = AxWebBrowser1.GetOcx();
IOleObject oc = obj as IOleObject;
oc.SetClientSite(this); // System.NullReferenceException
// Fix for OnBeforeNavigate .Net 1.0
ie_events = (SHDocVw.WebBrowserClass) Marshal.CreateWrapperOfType
(AxWebBrowser1.GetOcx(), typeof(SHDocVw.WebBrowserClass));
SHDocVw.DWebBrowserEvents_BeforeNavigateEventHandler BeforeNavigateE =
new SHDocVw.DWebBrowserEvents_BeforeNavigateEventHandler
(OnBeforeNavigate);
ie_events.BeforeNavigate +=
BeforeNavigateE;//System.NullReferenceException
}
If i Comment the both lines with // System.NullRefernceException it
runs, but with no BeforeNavigate Event, and not with the content menu -
which worked fine before creating it at runtime.
I tried several things, but running out of ideas and found nothing with

All it throws out is a System.NullReferenceException and that the object
ist not bound to the instance.
Maybe someone has done this before or can me give some hints.
Thanks for your Help
Matt