?
Solved

Embedding the IE to a VB.NET form.

Posted on 2005-02-24
5
Medium Priority
?
2,918 Views
Last Modified: 2012-08-14

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
0
Comment
Question by:mhertzDEV
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 12

Accepted Solution

by:
S-Twilley earned 1500 total points
ID: 13394505
On your toolbox.. goto customize

Check the "Microsoft Web Browser" control, this will add a control that you can add to your form instead of an IE instance
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13394520
You can control it much like the InternetExplorer object, except its embedded in your application. If you have any probs with it, just ask
0
 
LVL 9

Expert Comment

by:Lacutah
ID: 13394529
0
 

Author Comment

by:mhertzDEV
ID: 13395666
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_StatusTextChange(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_StatusTextChangeEvent) Handles AxWebBrowser1.StatusTextChange
        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.parentWindow.execScript("window.print();", "JScript")
    End Sub
End Class
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13395782
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
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question