Results 1 to 7 of 7

Thread: IE Webbrowser

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    IE Webbrowser

    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.

    Code:
    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?
    Attached Files Attached Files

  2. #2
    Addicted Member ZenDisaster's Avatar
    Join Date
    Dec 2006
    Location
    Bay Area, CA
    Posts
    140

    Re: IE Webbrowser

    Ouch, you're pulling teeth over there.

    I always just used the IEDOM.

    This is the code I use to create a new instance of IE;

    Code:
        Private Function NewIE() As Process
            Return Process.Start("iexplore.exe")
        End Function

    Once you've nabbed the instance of IE you can do anything.

    To add a new tab and make it active;

    Code:
    IE.Navigate("http://www.google.com/", 2048)
    To add an inactive tab;

    Code:
    IE.Navigate("http://www.google.com/", 4096)
    etc ...

    Here are your browser enum constants for the Navigate method's Flags

    Code:
    typedef enum BrowserNavConstants {
        navOpenInNewWindow = 0x1,
        navNoHistory = 0x2,
        navNoReadFromCache = 0x4,
        navNoWriteToCache = 0x8,
        navAllowAutosearch = 0x10,
        navBrowserBar = 0x20,
        navHyperlink = 0x40,
        navEnforceRestricted = 0x80,
        navNewWindowsManaged = 0x0100,
        navUntrustedForDownload = 0x0200,
        navTrustedForActiveX = 0x0400,
        navOpenInNewTab = 0x0800,
        navOpenInBackgroundTab = 0x1000,
        navKeepWordWheelText = 0x2000
    } BrowserNavConstants;
    Just change those Hex values to Decimal and pass them directly or create your own enum for VB.

    We could write a volume on the subject but Microsoft has already done that for us. You get the idea though ...

    In my humble opinion, this is the clean, fast, easy way.

  3. #3
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: IE Webbrowser

    Quote Originally Posted by ZenDisaster View Post
    Ouch, you're pulling teeth over there.

    I always just used the IEDOM.

    This is the code I use to create a new instance of IE;

    Code:
        Private Function NewIE() As Process
            Return Process.Start("iexplore.exe")
        End Function

    Once you've nabbed the instance of IE you can do anything.

    To add a new tab and make it active;

    Code:
    IE.Navigate("http://www.google.com/", 2048)
    To add an inactive tab;

    Code:
    IE.Navigate("http://www.google.com/", 4096)
    etc ...

    Here are your browser enum constants for the Navigate method's Flags

    Code:
    typedef enum BrowserNavConstants {
        navOpenInNewWindow = 0x1,
        navNoHistory = 0x2,
        navNoReadFromCache = 0x4,
        navNoWriteToCache = 0x8,
        navAllowAutosearch = 0x10,
        navBrowserBar = 0x20,
        navHyperlink = 0x40,
        navEnforceRestricted = 0x80,
        navNewWindowsManaged = 0x0100,
        navUntrustedForDownload = 0x0200,
        navTrustedForActiveX = 0x0400,
        navOpenInNewTab = 0x0800,
        navOpenInBackgroundTab = 0x1000,
        navKeepWordWheelText = 0x2000
    } BrowserNavConstants;
    Just change those Hex values to Decimal and pass them directly or create your own enum for VB.

    We could write a volume on the subject but Microsoft has already done that for us. You get the idea though ...

    In my humble opinion, this is the clean, fast, easy way.
    Thats a simple way of doing it... provided you don't need to embed the browser within your own application.

    Creating a new IE process is fine but it will be a separate entity to your core program, so for example if you close your new IE process your application is sat there with no browser, and vice-versa.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    Re: IE Webbrowser

    Sir i want to open the browers in mine project.....what is IEDOM?? plz explain me atleast to some extent more,plz its very urgent. Any help will be highly appreciated.

  5. #5
    Addicted Member ZenDisaster's Avatar
    Join Date
    Dec 2006
    Location
    Bay Area, CA
    Posts
    140

    Re: IE Webbrowser

    Madam, the provided information will not allow you to open IE as a child window of your application. Instead it starts IE in it's own window and controls it remotely.

    The IEDOM, or Internet Explorer Document Object Model was what I was referring to. The code I provided will allow you to control an instance of Internet Explorer. I appologize for providing you with information not relavant to your application.

    However, there is an API to force IE to become a bastard of your application. I just can't remember which it is at the moment. Still, it's probably not what you're looking for.

    Good luck in your endeavor.

  6. #6
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: IE Webbrowser

    It is exactly what she needs. The API is SetParent and needs to be complimented with an api combination that kind of hides the control box of the IE window (tutorial here).
    VB 2005, Win Xp Pro sp2

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2008
    Posts
    474

    Re: IE Webbrowser

    hello sir half,i want to create an IE webbrowser..just like similar..on pressing CTRL + T...,new tab goes on adding...& also if we type in textbox the url...tab that is currently active,navigate to the URL..i dont think so the dreamincode material is relevant to dat...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width