Support
Joined: 18 Jul 2005 Posts: 731
|
Posted: Fri Jan 25, 2008 2:15 am Post subject: HOWTO : Interact with IE from a Band Object or a Browser Helper Object |
|
|
It is often necessary to interact with IE from a band object or a browser helper object by accessing its various methods, properties and events. Use the following code to get a reference to the IE instance :
[C#]
object o = this.GetWebBrowser();
if(o!=null)
{
SHDocVw.WebBrowserClass wbc = (SHDocVw.WebBrowserClass)Marshal.CreateWrapperOfType(o,typeof(SHDocVw.WebBrowserClass));
// Use the Navigate method to browse to a specific URL
object dummy = null;
wbc.Navigate("http://www.ssware.com",ref dummy,ref dummy,ref dummy,ref dummy);
}
[VB.Net]
Dim o As Object = Me.GetWebBrowser()
If (o Is Nothing = False) Then
Dim wbc As SHDocVw.WebBrowserClass = CType(Marshal.CreateWrapperOfType(o, GetType(SHDocVw.WebBrowserClass)), SHDocVw.WebBrowserClass)
' Use the Navigate method to browse to a specific URL
Dim dummy As Object = Nothing
wbc.Navigate("http://www.ssware.com", dummy, dummy, dummy, dummy)
Note:
Your project must add a reference to "Microsoft Internet Controls" (ShDocVw.dll) from the COM tab of the 'Add Reference..' dialog box. The interop assembly file generated - "Interop.ShDocVw.dll" - should be given a strong name and be placed in the GAC. To give a strong name to the file, goto project properties and specify a key file/ key name in the 'Wrapper Assembly For ActiveX/COM objects heading.
Alternatively, you can use the "Interop.ShDocVw.dll" that comes with EZShellExtensions.Net; it is located in the install path (typically C:\Program Files\LogicNP Software\EZShellExtensions.Net 2.0). |
|