Click here to Skip to main content
15,886,724 members
Articles / Programming Languages / Visual Basic

Working with the Web Browser Control in Visual Studio 2005 - IE7Clone.

Rate me:
Please Sign up or sign in to vote.
4.89/5 (65 votes)
14 Jan 20076 min read 587.6K   12.1K   150  
Example application working with the VS2005 Web browser control
'This for facilitates adding of new search providers.
'Thomas Maxwell - 2007.
Imports System.Data.OleDb
Public Class frmAddSearchProvider

    Public strXML As String
    Dim oDs As New DataSet

    Private Sub frmAddSearchProvider_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        oDs.Dispose()
    End Sub

    Private Sub frmAddSearchProvider_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Here we are just using a simple method to read the xml file so we can 
        'add it to our own internal search provider datatable. Obviously you might want to
        'read the xml in a different way, for this example application...this does the trick.
        Label1.Text = "Do you want to add the following search provider to " & My.Resources.AppName & "?"
        Try
            oDs.ReadXml(Trim(strXML))
            Dim ofrm As New frmAddSearchProvider
            lblName.Text = AppManager.CurrentBrowser.Document.Domain
            lblFrom.Text = oDs.Tables(0).Rows(0).Item("ShortName")
        Catch ex As Exception
            MsgBox(ex.Message.ToString)
        End Try
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        If chkDefault.Checked Then
            setdefault()
        End If
        AddProvider()
    End Sub

    Private Sub AddProvider()
        'In this example application, we do not care if a user adds more than 1
        'of the same provider, so we will not check for that.
        Dim oConn As New OleDbConnection(AppManager.ConnString)
        Dim strSQL As String = _
        "INSERT INTO SearchProviders (ProviderTitle, ProviderURL, IsDefault) VALUES " & _
        "('" & oDs.Tables(0).Rows(0).Item("ShortName") & _
        "', '" & oDs.Tables(1).Rows(0).Item("Template") & _
        "', " & chkDefault.Checked & ")"
        Dim oCmd As New OleDbCommand(strSQL, oConn)

        Try
            oConn.Open()
            oCmd.ExecuteNonQuery()
            oConn.Close()
            AppManager.MainForm.LoadSearchProviders()
            Me.Close()
        Catch ex As Exception
            MsgBox(ex.Message.ToString)
        End Try

    End Sub

    Private Sub SetDefault()
        Dim strSQL As String = "Update SearchProviders Set IsDefault=False"
        Dim oConn As New OleDbConnection(AppManager.ConnString)
        Dim oCmd As New OleDbCommand(strSQL, oConn)
        Try
            oConn.Open()
            oCmd.ExecuteNonQuery()
            oConn.Close()
        Catch ex As Exception
            MsgBox(ex.Message.ToString)
        Finally
            oConn.Dispose()
            oCmd.Dispose()
        End Try
    End Sub

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
I have played various roles in IT since around 1993 when I began writing commercial web pages. I then moved to mainly coding in Visual Basic around 1995, making point of sale and kiosk systems, more recently moving to e-commerce and crm applications. Since the release of .net I have been mainly working in .net focusing in vb.net although I have done several projects in c#. I have worked for various companies and have held the position of lead developer at several, recently (2005) leading the e-commerce team at a national retailer to a successful e-commerce implementation. I currently hold comptia a+, network plus, mcp, mcsa, mcse (server system 2003) and mcsd certifications. I enjoy sharing what I have learned as well as embracing new technologies as they are released.

Comments and Discussions