mhertzDEV
asked on
Embedding the IE to a VB.NET form.
Hello:
I'm trying to create an application that will allow me to embed IE into a VB.NET (2003) form.
My idea is to have something like this:
' being vb.net form
--------------------------
(back) - (forward) - (stop) - (refresh)
--------------------------
DISPLAY HTML PAGES
--------------------------
' end vb.net form
In other words the form will have like a top part with the buttons or controls like back, forward,
stop, etc. and the bottom part is where the actual HTML will be display. The URL’s will be hardcoded
in the code.
I assuming the way to do this is by embedding the IE Object into the form, so far I’m using "shdocvw"
my code looks as follows, but it opens a NEW IE window. I need it to be embedded into the form and have
the ability to control it and go back, forward, stop, etc.
' VB.NET 2003 CODE
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
[....]
#End Region
Public WithEvents IE As SHDocVw.InternetExplorer
Public Sub Form1_Load()
End Sub
Private Sub Form1_Unload()
IE.Quit()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
IE = New SHDocVw.InternetExplorer
IE.Visible = True
IE.MenuBar = False
IE.AddressBar = False
IE.ToolBar = False
IE.Navigate("http://www.yahoo.com")
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can control it much like the InternetExplorer object, except its embedded in your application. If you have any probs with it, just ask
ASKER
Thanks a lot S-Twilley...
Here is my current code, to help the next guy =)
Any suggestions will still be appreciated.
' BEING VB.NET CODE
Imports
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
[.......]
#End Region
Public Shared Function Main(ByVal args() As String) As Integer
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AxWebBrowser1.Visible = True
AxWebBrowser1.AddressBar = True
AxWebBrowser1.Navigate("http://www.yahoo.com")
End Sub
Private Sub btnGoBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGoBack.Click
'If there is nothing to go back too and we click GoBack,
'it will try to access an object that doesnt exists and
'BIGBADABOOM! Unless we next it =)
On Error Resume Next
AxWebBrowser1.GoBack()
End Sub
Private Sub btnGoForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGoForward.Click
'If there is nothing to go forward too and we click GoForward,
'it will try to access an object that doesnt exists and
'BIGBADABOOM! Unless we next it =)
On Error Resume Next
AxWebBrowser1.GoForward()
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
AxWebBrowser1.Stop()
End Sub
Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
AxWebBrowser1.Refresh2()
End Sub
Private Sub AxWebBrowser1_StatusTextCh ange(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvent s2_StatusT extChangeE vent) Handles AxWebBrowser1.StatusTextCh ange
StatusBar1.Text = AxWebBrowser1.StatusText
End Sub
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
'AxWebBrowser Printing current document with Print Dialog
AxWebBrowser1.Document.par entWindow. execScript ("window.p rint();", "JScript")
End Sub
End Class
Here is my current code, to help the next guy =)
Any suggestions will still be appreciated.
' BEING VB.NET CODE
Imports
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
[.......]
#End Region
Public Shared Function Main(ByVal args() As String) As Integer
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AxWebBrowser1.Visible = True
AxWebBrowser1.AddressBar = True
AxWebBrowser1.Navigate("http://www.yahoo.com")
End Sub
Private Sub btnGoBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGoBack.Click
'If there is nothing to go back too and we click GoBack,
'it will try to access an object that doesnt exists and
'BIGBADABOOM! Unless we next it =)
On Error Resume Next
AxWebBrowser1.GoBack()
End Sub
Private Sub btnGoForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGoForward.Click
'If there is nothing to go forward too and we click GoForward,
'it will try to access an object that doesnt exists and
'BIGBADABOOM! Unless we next it =)
On Error Resume Next
AxWebBrowser1.GoForward()
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
AxWebBrowser1.Stop()
End Sub
Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
AxWebBrowser1.Refresh2()
End Sub
Private Sub AxWebBrowser1_StatusTextCh
StatusBar1.Text = AxWebBrowser1.StatusText
End Sub
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
'AxWebBrowser Printing current document with Print Dialog
AxWebBrowser1.Document.par
End Sub
End Class
I'd use the Try catch block instead of Resume next, might not make much of a difference here, but it's a more powerful error handling method:
Try
AxWebBrowser1.GoBack()
Catch e as exception
'Im guessing you're just ignoring errors so don't do anything here
End Try
===================
Also add a textbox so you can choose where to navigate to (change webpage on enter being pressed... or a Go button)
To match this, on the NavigateComplete event of the browser control. Add the line
txtAddress.Text = AxWebBrowser1.LocationURL
Note: the navigatecomplete event is fired for subframes as well, but the property returns from AxWebBrowser1 is the hosting webpage
===================
You may also want to rename the control to something shorter, cos in my experience, you'll be typing that out alot
===================
I'd put the web control in it's own panel, and set the dock property of it to fill. Then anchor the panel to all sides, so that when you resize the window, it follows it around
Try
AxWebBrowser1.GoBack()
Catch e as exception
'Im guessing you're just ignoring errors so don't do anything here
End Try
===================
Also add a textbox so you can choose where to navigate to (change webpage on enter being pressed... or a Go button)
To match this, on the NavigateComplete event of the browser control. Add the line
txtAddress.Text = AxWebBrowser1.LocationURL
Note: the navigatecomplete event is fired for subframes as well, but the property returns from AxWebBrowser1 is the hosting webpage
===================
You may also want to rename the control to something shorter, cos in my experience, you'll be typing that out alot
===================
I'd put the web control in it's own panel, and set the dock property of it to fill. Then anchor the panel to all sides, so that when you resize the window, it follows it around