I have a aplication which hosts an axWebbrowser. This activex component needs about 10 to 15 mb of memory.
Because i have a option to move the aplication to tray icon and do some timer work i don't want that it just spends over 10mb for nothing.
So i remove the axwebbrowser with
axwebbrowser1.dispose()
which works fine. After show the application back from the tray icon i will
implement the axwebbrowser again with the same i did it before:
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmMain));
this.axWebBrowser1 = new AxSHDocVw.AxWebBrowser();
// Tell the axwebbrowser that the main form controls the ie :)
object obj = axWebBrowser1.GetOcx();
IOleObject oc = obj as IOleObject;
oc.SetClientSite(this);
// Some events we want to have
ie_events = (SHDocVw.WebBrowserClass) Marshal.CreateWrapperOfType(axWebBrowser1.GetOcx() , typeof(SHDocVw.WebBrowserClass));
SHDocVw.DWebBrowserEvents_BeforeNavigateEventHandl er BeforeNavigateE = new SHDocVw.DWebBrowserEvents_BeforeNavigateEventHandl er(OnBeforeNavigate);
ie_events.BeforeNavigate += BeforeNavigateE;
// The basic stuff to set the axwebbrowser into the form
((System.ComponentModel.ISupportInitialize)(this.a xWebBrowser1)).BeginInit();
this.panel1.Controls.Add(this.axWebBrowser1);
this.axWebBrowser1.ContainingControl = this;
this.axWebBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
this.axWebBrowser1.Enabled = true;
this.axWebBrowser1.Location = new System.Drawing.Point(0, 0);
this.axWebBrowser1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.Get Object("axWebBrowser1.OcxState")));
this.axWebBrowser1.Size = new System.Drawing.Size(100, 100);
this.axWebBrowser1.TabIndex = 0;
this.axWebBrowser1.NavigateComplete2 += new AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Even tHandler(this.axWebBrowser1_NavigateComplete2);
((System.ComponentModel.ISupportInitialize)(this.a xWebBrowser1)).EndInit();
If i remove the oc.setclientsite(this) it works without any errors, but i can't control the ie on the full way
(the user content menu doesn't work) - but when i insert this line i get the error:
object not at object instance (translated from my german version :) )
At my app i use the iolecliensite, idochostuihandler, ioledocumentsite and idochostshowui methods.
at the idochostuihandler i implemented the context-menu routine:
public uint ShowContextMenu(uint dwID, ref tagPOINT ppt, object pcmdtReserved, object pdispReserved)
{
// use this code to show a custom menu
const int MenuHandled = 0;
Point p = new Point(ppt.x, ppt.y);
p = PointToClient(p);
ie_cmenu.Show(this, p);
return MenuHandled;
}
Or has anyone a idea how to free the memory from the axwebbrowser? But i want the component
back after showing the form again ;)
thanks
Matthias