I m working on project in which i have to add tab & close tab as that of IE.
I m able to do dat,but its not very much clean.Check it out.Plz see if somebody can help me to do it more better.

Public Class Form5
    Public lSelectedTabPageIndex As Integer
    Public CurrentWEB As WebBrowser

    Public Sub New()
        MyBase.New()
        InitializeComponent()
        TabWebBrowsers.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed
    End Sub

    Private Sub mnuAddTab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAddTab.Click
        Try
            lSelectedTabPageIndex = lSelectedTabPageIndex + 1
            Call AddNewTabInTabWebBrowsers(True, True)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub AddNewTabInTabWebBrowsers(ByVal bMakeTab As Boolean, ByVal bMakeWebBrowser As Boolean)
        Static lTabPageCount As Integer = 1

        If bMakeTab Then
            Dim tab As TabPage = New TabPage("Connecting...")
            tab.Name = "tab" & lTabPageCount
            tab.Tag = "http://www.google.com"
            tab.ImageIndex = 0
            TabWebBrowsers.TabPages.Add(tab)
            TabWebBrowsers.SelectedIndex = TabWebBrowsers.TabPages.Count - 1
            lSelectedTabPageIndex = TabWebBrowsers.TabPages.Count - 1
            lTabPageCount = lTabPageCount + 1
            If TabWebBrowsers.TabPages.Count > 1 Then
                ContextmnuCloseTab.Enabled = True
            End If
        End If

        If bMakeWebBrowser Then Call AddWebBrowserATRUNTIME(bMakeTab)
    End Sub

    Private Sub AddWebBrowserATRUNTIME(ByVal bMakeTab As Boolean)
        Try
            Dim WEB As New WebBrowser
            Static lWEBCount As Integer = 0
            WEB.Name = "Wbr" & lWEBCount
            WEB.Size = New Size(731, 354)
            WEB.Location = New Point(3, 3)
            If bMakeTab = False Then
                WEB.Navigate("http://www.google.com")
            Else
                WEB.Navigate("about:blank")
            End If

            TabWebBrowsers.TabPages.Item(TabWebBrowsers.TabPages.Count - 1).Controls.Add(WEB)
            lWEBCount = lWEBCount + 1
            TabWebBrowsers.Refresh()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub TabWebBrowsers_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles TabWebBrowsers.DrawItem
        Try
            Dim _imageLocation As Point = New Point(15, 4)
            Dim g As Graphics = e.Graphics
            Dim tp As TabPage = TabWebBrowsers.TabPages(e.Index)
            Dim br As Brush
            Dim sf As New StringFormat

            Dim rold As New RectangleF(e.Bounds.X, e.Bounds.Y + 2, e.Bounds.Width, e.Bounds.Height - 2)

            sf.Alignment = StringAlignment.Center

            Dim strTitle As String = tp.Text

            br = New SolidBrush(Color.LightBlue) ' Change this to your preference
            g.FillRectangle(br, e.Bounds)
            br = New SolidBrush(Color.Black)
            g.DrawString(strTitle, TabWebBrowsers.Font, br, rold, sf)

            Dim img As Image = ImgCommon.Images(0)  'ImgIcons.Images(1) MONISH
            Dim r1 As Rectangle = e.Bounds
            r1 = Me.TabWebBrowsers.GetTabRect(e.Index)
            r1.Offset(2, 2)

            Dim TitleBrush As Brush = New SolidBrush(Color.Black)
            Dim f As Font = Me.Font

            Dim title As String = Me.TabWebBrowsers.TabPages(e.Index).Text
            e.Graphics.DrawImage(img, New Point(r1.X + (Me.TabWebBrowsers.GetTabRect(e.Index).Width - _imageLocation.X) - 10, _imageLocation.Y + 2))
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Call AddNewTabInTabWebBrowsers(False, True)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub ContextmnuCloseTab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContextmnuCloseTab.Click
        Try

            If lSelectedTabPageIndex + 1 = TabWebBrowsers.TabPages.Count Then
                lSelectedTabPageIndex = lSelectedTabPageIndex - 1
            End If

            With Me.TabWebBrowsers.TabPages
                .Remove(.Item(lSelectedTabPageIndex))
            End With

            With Me.TabWebBrowsers
                .SelectedIndex = lSelectedTabPageIndex
                .Refresh()
            End With

            If TabWebBrowsers.TabPages.Count = 1 Then
                ContextmnuCloseTab.Enabled = False
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub TabWebBrowsers_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TabWebBrowsers.MouseUp
        Try
            Dim tabIndex As Integer
            tabIndex = GetTabIndex(e.Location)
            If tabIndex <> -1 Then
                lSelectedTabPageIndex = CInt(tabIndex.ToString("F0"))
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Function GetTabIndex(ByVal p As Point) As Integer
        Dim result As Integer = -1
        Dim i1 As Integer
        For i1 = 0 To TabWebBrowsers.TabPages.Count - 1
            If TabWebBrowsers.GetTabRect(i1).Contains(p) Then
                GetTabIndex = i1
            End If
        Next
    End Function
End Class

In first tab i m opening google.On other tabs i m opening blank.
I m facing just simple probs in close tab,Suppose i click on first tab that is google,then right click on second tab(tab haeder) to close it...When tab is close,First just a min, google tab is shown then selected tab is shown....I dont want to show even a google tab for a min...


Is there any easy way to craete IE browser..is there any IE Browsr control in VB.Net?

I m working on project in which i have to add tab & close tab as that of IE.
I m able to do dat,but its not very much clean.Check it out.Plz see if somebody can help me to do it more better.

Public Class Form5
    Public lSelectedTabPageIndex As Integer
    Public CurrentWEB As WebBrowser

    Public Sub New()
        MyBase.New()
        InitializeComponent()
        TabWebBrowsers.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed
    End Sub

    Private Sub mnuAddTab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAddTab.Click
        Try
            lSelectedTabPageIndex = lSelectedTabPageIndex + 1
            Call AddNewTabInTabWebBrowsers(True, True)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub AddNewTabInTabWebBrowsers(ByVal bMakeTab As Boolean, ByVal bMakeWebBrowser As Boolean)
        Static lTabPageCount As Integer = 1

        If bMakeTab Then
            Dim tab As TabPage = New TabPage("Connecting...")
            tab.Name = "tab" & lTabPageCount
            tab.Tag = "http://www.google.com"
            tab.ImageIndex = 0
            TabWebBrowsers.TabPages.Add(tab)
            TabWebBrowsers.SelectedIndex = TabWebBrowsers.TabPages.Count - 1
            lSelectedTabPageIndex = TabWebBrowsers.TabPages.Count - 1
            lTabPageCount = lTabPageCount + 1
            If TabWebBrowsers.TabPages.Count > 1 Then
                ContextmnuCloseTab.Enabled = True
            End If
        End If

        If bMakeWebBrowser Then Call AddWebBrowserATRUNTIME(bMakeTab)
    End Sub

    Private Sub AddWebBrowserATRUNTIME(ByVal bMakeTab As Boolean)
        Try
            Dim WEB As New WebBrowser
            Static lWEBCount As Integer = 0
            WEB.Name = "Wbr" & lWEBCount
            WEB.Size = New Size(731, 354)
            WEB.Location = New Point(3, 3)
            If bMakeTab = False Then
                WEB.Navigate("http://www.google.com")
            Else
                WEB.Navigate("about:blank")
            End If

            TabWebBrowsers.TabPages.Item(TabWebBrowsers.TabPages.Count - 1).Controls.Add(WEB)
            lWEBCount = lWEBCount + 1
            TabWebBrowsers.Refresh()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub TabWebBrowsers_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles TabWebBrowsers.DrawItem
        Try
            Dim _imageLocation As Point = New Point(15, 4)
            Dim g As Graphics = e.Graphics
            Dim tp As TabPage = TabWebBrowsers.TabPages(e.Index)
            Dim br As Brush
            Dim sf As New StringFormat

            Dim rold As New RectangleF(e.Bounds.X, e.Bounds.Y + 2, e.Bounds.Width, e.Bounds.Height - 2)

            sf.Alignment = StringAlignment.Center

            Dim strTitle As String = tp.Text

            br = New SolidBrush(Color.LightBlue) ' Change this to your preference
            g.FillRectangle(br, e.Bounds)
            br = New SolidBrush(Color.Black)
            g.DrawString(strTitle, TabWebBrowsers.Font, br, rold, sf)

            Dim img As Image = ImgCommon.Images(0)  'ImgIcons.Images(1) MONISH
            Dim r1 As Rectangle = e.Bounds
            r1 = Me.TabWebBrowsers.GetTabRect(e.Index)
            r1.Offset(2, 2)

            Dim TitleBrush As Brush = New SolidBrush(Color.Black)
            Dim f As Font = Me.Font

            Dim title As String = Me.TabWebBrowsers.TabPages(e.Index).Text
            e.Graphics.DrawImage(img, New Point(r1.X + (Me.TabWebBrowsers.GetTabRect(e.Index).Width - _imageLocation.X) - 10, _imageLocation.Y + 2))
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Call AddNewTabInTabWebBrowsers(False, True)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub ContextmnuCloseTab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContextmnuCloseTab.Click
        Try

            If lSelectedTabPageIndex + 1 = TabWebBrowsers.TabPages.Count Then
                lSelectedTabPageIndex = lSelectedTabPageIndex - 1
            End If

            With Me.TabWebBrowsers.TabPages
                .Remove(.Item(lSelectedTabPageIndex))
            End With

            With Me.TabWebBrowsers
                .SelectedIndex = lSelectedTabPageIndex
                .Refresh()
            End With

            If TabWebBrowsers.TabPages.Count = 1 Then
                ContextmnuCloseTab.Enabled = False
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub TabWebBrowsers_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TabWebBrowsers.MouseUp
        Try
            Dim tabIndex As Integer
            tabIndex = GetTabIndex(e.Location)
            If tabIndex <> -1 Then
                lSelectedTabPageIndex = CInt(tabIndex.ToString("F0"))
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Function GetTabIndex(ByVal p As Point) As Integer
        Dim result As Integer = -1
        Dim i1 As Integer
        For i1 = 0 To TabWebBrowsers.TabPages.Count - 1
            If TabWebBrowsers.GetTabRect(i1).Contains(p) Then
                GetTabIndex = i1
            End If
        Next
    End Function
End Class

In first tab i m opening google.On other tabs i m opening blank.
I m facing just simple probs in close tab,Suppose i click on first tab that is google,then right click on second tab(tab haeder) to close it...When tab is close,First just a min, google tab is shown then selected tab is shown....I dont want to show even a google tab for a min...


Is there any easy way to craete IE browser..is there any IE Browsr control in VB.Net?

I ran that code through my ever great code scaner, and it is not finding ANY errors. But, if you want to make a web browser, I have a video tutorial that is attached to this message. If you don't want that, then you need to add items by doing this:

Visual Basic> Tools> Chose Toolbox Itmes..

From there, look through both COM and .NET untill you find a webbrowser. And that is a IE browser window, you need to add your own navigation bars and such. If you want more help, Just ask!

But i also have the codes right here for you:

Public Class Form1
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        WebBrowser1.Navigate("http://www.google.com/search?hl=en&q=" & TextBox2.Text & "&btnG=Google+Search&meta=")
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WebBrowser1.Navigate(TextBox1.Text)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        WebBrowser1.Refresh()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        WebBrowser1.GoBack()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        WebBrowser1.GoForward()
    End Sub
    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        StatusStrip1.Visible = True
        ToolStripProgressBar1.Value = 0
    End Sub

    Private Sub WebBrowser1_ProgressChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged
        Dim CurProg As Single
        Dim MaxProg As Single
        CurProg = e.CurrentProgress
        MaxProg = e.MaximumProgress
        ToolStripProgressBar1.Value = (CurProg / MaxProg) * 100
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        WebBrowser1.Stop()
    End Sub
End Class

There is no error in code,have u run the code..Its too lengthy process of IE Browser..Frnd i have added web browser in the similar way..I want an easy method of buliding IE Webbrowser...can u plz give me the idea..

There is no error in code,have u run the code..Its too lengthy process of IE Browser..Frnd i have added web browser in the similar way..I want an easy method of buliding IE Webbrowser...can u plz give me the idea..

I will send a a message with my web browser in it. take a look at that.

I don't have a lot of time, so i can give you a tutorial.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.