Imports System.Windows.Forms, System.Drawing
Public Class Tabbed_IE
#Region "Public Variables"
Public MyURL As String
Public MyLink As String
Public MySource As String
Public CurrentBrowser As WebBrowser
Public DocTitle As String
Public ImgName As String
Public WithEvents NewURL As New myVar
Public WithEvents CurrentDocument As HtmlDocument
Public MousePoint As New Point
Public Ele As HtmlElement
Public Ment As HtmlElement
Public Linx As String
Public Sauce As String
Public HomePage As String
#End Region
Private Sub Tabbed_IE_Disposed(sender As Object, e As System.EventArgs) Handles Me.Disposed
My.Settings.HomePage = HomePage
My.Settings.Save()
End Sub
Private Sub Tabbed_IE_Load(sender As Object, e As System.EventArgs) Handles Me.Load, MyBase.Load
AddHandler Web1.DocumentCompleted, AddressOf IELoaded
Me.Anchor = AnchorStyles.Left Or AnchorStyles.Right Or AnchorStyles.Top Or AnchorStyles.Bottom
End Sub
Private Sub VariableChanged(ByVal NewValue As String) Handles NewURL.VariableChanged
DirectCast(Me.Tabby.SelectedTab.Controls(0), WebBrowser).Navigate(NewValue)
End Sub
Private Sub OpenInNewTabToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles OpenInNewTabToolStripMenuItem.Click
' create a new webbrowser instance on new tab
Dim tabpage As New TabPage("This is New Tab")
Me.Tabby.TabPages.Add(tabpage)
Dim web1 As New WebBrowser
web1.Name = "Web1"
web1.Dock = DockStyle.Fill
' re associate contextmenustrip for each webbrowser instance
web1.IsWebBrowserContextMenuEnabled = False
web1.ContextMenuStrip = Menu1
web1.ScriptErrorsSuppressed = True
Dim target As String
target = (DirectCast(Me.Tabby.SelectedTab.Controls(0), WebBrowser).Document.ActiveElement.GetAttribute("href"))
web1.Navigate(target)
AddHandler web1.NewWindow, AddressOf Web1_NewWindow
AddHandler web1.DocumentCompleted, AddressOf IELoaded
tabpage.Controls.Add(web1)
Me.Tabby.SelectedTab = tabpage
End Sub
Private Sub IELoaded(ByVal sender As Object, e As WebBrowserDocumentCompletedEventArgs)
CurrentBrowser = CType(Tabby.SelectedTab.Controls(0), WebBrowser)
CurrentDocument = CType(Tabby.SelectedTab.Controls(0), WebBrowser).Document
DocTitle = CType(Tabby.SelectedTab.Controls(0), WebBrowser).DocumentTitle
MyLink = CType(Tabby.SelectedTab.Controls(0), WebBrowser).Url.ToString
If Ele IsNot Nothing Then
If Ele.TagName = "IMG" Then
If ImgName IsNot Nothing Then
Tabby.SelectedTab.Text = ImgName
Tabby.SelectedTab.ToolTipText = Tabby.SelectedTab.Text
AddressBar.Text = MyLink
ImgName = Nothing
Ele = Nothing
End If
Else
Tabby.SelectedTab.Text = DocTitle
Tabby.SelectedTab.ToolTipText = Tabby.SelectedTab.Text
AddressBar.Text = MyLink
Ele = Nothing
End If
Else
If DocTitle IsNot Nothing And MyLink IsNot Nothing Then
Tabby.SelectedTab.Text = DocTitle
Tabby.SelectedTab.ToolTipText = Tabby.SelectedTab.Text
AddressBar.Text = MyLink
End If
End If
CurrentBrowser.Focus()
End Sub
Private Sub AddressBar_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles AddressBar.KeyDown
If e.KeyCode = Keys.Enter Then
Go()
End If
End Sub
Public Sub Go()
If AddressBar.Text <> Nothing Then
DirectCast(Me.Tabby.SelectedTab.Controls(0), WebBrowser).Navigate(AddressBar.Text)
End If
End Sub
Public Sub NewTab()
' create a new webbrowser instance on new tab
Dim web1 As New WebBrowser
web1.Name = "Web1"
web1.Dock = DockStyle.Fill
' re associate contextmenustrip for each webbrowser instance
web1.IsWebBrowserContextMenuEnabled = False
web1.ContextMenuStrip = Menu1
web1.ScriptErrorsSuppressed = True
AddHandler web1.NewWindow, AddressOf Web1_NewWindow
AddHandler web1.DocumentCompleted, AddressOf IELoaded
Dim tabpage As New TabPage("This is New Tab")
tabpage.Controls.Add(web1)
Me.Tabby.TabPages.Add(tabpage)
Me.Tabby.SelectedTab = tabpage
DirectCast(Me.Tabby.SelectedTab.Controls(0), WebBrowser).Navigate("www.google.com")
End Sub
Private Sub Web1_NewWindow(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles Web1.NewWindow
e.Cancel = True
' create a new webbrowser instance on new tab
Dim tabpage As New TabPage("This is New Tab")
Me.Tabby.TabPages.Add(tabpage)
Dim web1 As New WebBrowser
web1.Name = "Web1"
web1.Dock = DockStyle.Fill
' re associate contextmenustrip for each webbrowser instance
web1.IsWebBrowserContextMenuEnabled = False
web1.ContextMenuStrip = Menu1
web1.ScriptErrorsSuppressed = True
web1.Navigate(Linx)
AddHandler web1.NewWindow, AddressOf Web1_NewWindow
AddHandler web1.DocumentCompleted, AddressOf IELoaded
tabpage.Controls.Add(web1)
Me.Tabby.SelectedTab = tabpage
End Sub
Private Sub Tabby_DoubleClick(sender As Object, e As System.EventArgs) Handles Tabby.DoubleClick
Tabby.SelectedTab.Dispose()
End Sub
Private Sub Tabby_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles Tabby.SelectedIndexChanged
If Tabby.TabCount > 0 Then
CurrentBrowser = CType(Tabby.SelectedTab.Controls(0), WebBrowser)
CurrentDocument = CType(Tabby.SelectedTab.Controls(0), WebBrowser).Document
Dim Target As Uri = CType(Tabby.SelectedTab.Controls(0), WebBrowser).Url
If Target IsNot Nothing Then
AddressBar.Text = Target.ToString
MyURL = Target.ToString
End If
End If
End Sub
Private Sub SaveImageAsToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SaveImageToolStripMenuItem.Click
Dim ImageSource As String = Ele.GetAttribute("src")
MySource = ImageSource
Dim SavePath As String = InputBox("Please enter where you want to save this image, including the file name and extension")
My.Computer.Network.DownloadFile(ImageSource, SavePath)
End Sub
Private Sub ViewImageToolStripMenuItem_Click(sender As Object, e As System.EventArgs) Handles ViewImageToolStripMenuItem.Click
' create a new webbrowser instance on new tab
Dim tabpage As New TabPage("This is New Tab")
Me.Tabby.TabPages.Add(tabpage)
Dim web1 As New WebBrowser
web1.Name = "Web1"
web1.Dock = DockStyle.Fill
' re associate contextmenustrip for each webbrowser instance
web1.IsWebBrowserContextMenuEnabled = False
web1.ContextMenuStrip = Menu1
Dim target As String = Ele.GetAttribute("src")
ImgName = target.Substring(target.LastIndexOf("/") + 1)
web1.Navigate(target)
AddHandler web1.NewWindow, AddressOf Web1_NewWindow
AddHandler web1.DocumentCompleted, AddressOf IELoaded
tabpage.Controls.Add(web1)
Me.Tabby.SelectedTab = tabpage
End Sub
Private Sub hover(ByVal sender As Object, ByVal e As HtmlElementEventArgs) Handles CurrentDocument.MouseMove
MousePoint = e.ClientMousePosition
Ment = CurrentBrowser.Document.GetElementFromPoint(MousePoint)
Linx = Ment.GetAttribute("href")
Sauce = Ment.GetAttribute("src")
'Ele = CurrentBrowser.Document.GetElementFromPoint(MousePoint)
'Dim target As String = Ele.GetAttribute("src")
'AddressBar.Text = e.ClientMousePosition.ToString & Environment.NewLine & target.ToString
End Sub
Private Sub Menu1_Opening(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles Menu1.Opening
Ele = CurrentBrowser.Document.GetElementFromPoint(MousePoint)
'If Ele.TagName = "A" Then
' LinkToolStripMenuItem.Visible = True
'Else
' LinkToolStripMenuItem.Visible = False
'End If
'If Ele.TagName = "IMG" Then
' ImageToolStripMenuItem.Visible = True
'Else
' ImageToolStripMenuItem.Visible = False
'End If
End Sub
Private Sub CopyLinkLocationToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles CopyLinkLocationToolStripMenuItem.Click
Dim target As String = Ele.GetAttribute("href")
Clipboard.SetText(target)
End Sub
Private Sub CopyImageLocationToolStripMenuItem_Click(sender As Object, e As System.EventArgs) Handles CopyImageLocationToolStripMenuItem.Click
Dim target As String = Ele.GetAttribute("src")
Clipboard.SetText(target)
End Sub
Private Sub GoBackToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles GoBackToolStripMenuItem.Click
GoBack()
End Sub
Public Sub GoBack()
If CType(Tabby.SelectedTab.Controls(0), WebBrowser).CanGoBack = True Then
CType(Tabby.SelectedTab.Controls(0), WebBrowser).GoBack()
End If
End Sub
Private Sub GoForwardToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles GoForwardToolStripMenuItem.Click
Fwd()
End Sub
Public Sub Fwd()
If CType(Tabby.SelectedTab.Controls(0), WebBrowser).CanGoForward = True Then
CType(Tabby.SelectedTab.Controls(0), WebBrowser).GoForward()
End If
End Sub
Private Sub RefreshToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles RefreshToolStripMenuItem.Click
Refresher()
End Sub
Public Sub Refresher()
CType(Tabby.SelectedTab.Controls(0), WebBrowser).Refresh()
End Sub
Private Sub HomeToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles HomeToolStripMenuItem.Click
GoHome()
End Sub
Public Sub GoHome()
If Not My.Settings.HomePage = Nothing Then
CType(Tabby.SelectedTab.Controls(0), WebBrowser).Navigate(My.Settings.HomePage)
Else
CType(Tabby.SelectedTab.Controls(0), WebBrowser).Navigate("www.google.com")
End If
End Sub
Private Sub ChooseNewHomeToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ChooseNewHomeToolStripMenuItem.Click
HomePage = InputBox("Enter the URL you want to be your new home page.")
My.Settings.HomePage = HomePage
My.Settings.Save()
End Sub
Private Sub CopyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyToolStripMenuItem.Click
CType(Tabby.SelectedTab.Controls(0), WebBrowser).Document.ExecCommand("COPY", False, Nothing)
Clipboard.SetText(Trim(Clipboard.GetText))
End Sub
Private Sub PasteToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles PasteToolStripMenuItem.Click
CType(Tabby.SelectedTab.Controls(0), WebBrowser).Document.ExecCommand("PASTE", False, Nothing)
End Sub
Private Sub OpenLinkInDefaultBrowserToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles OpenLinkInDefaultBrowserToolStripMenuItem.Click
System.Windows.Forms.Cursor.Current = Cursors.AppStarting
Dim target As String
target = (DirectCast(Me.Tabby.SelectedTab.Controls(0), WebBrowser).Document.ActiveElement.GetAttribute("href"))
BrowserExec.LaunchNewBrowser(target)
System.Windows.Forms.Cursor.Current = Cursors.Default
End Sub
End Class
Imports System.IO, System.Net, System.Drawing
Imports System.Windows.Forms
Public Class Class1
End Class
Public Class Tabbed_Browers
Public Shared Function GetWebImage(ByVal ImageURL As String) As Image
Dim objImage As MemoryStream
Dim objwebClient As WebClient
Dim sURL As String = Trim(ImageURL)
Dim oImage As Image
Try
If Not sURL.ToLower().StartsWith("http://") _
Then sURL = "http://" & sURL
objwebClient = New WebClient
objImage = New _
MemoryStream(objwebClient.DownloadData(sURL))
oImage = System.Drawing.Image.FromStream(objImage)
Return oImage
Catch ex As Exception
'Return something, an error or no image as default
Return Nothing
End Try
End Function
End Class
Public Class myVar
Public mValue As String
Public Event VariableChanged(ByVal mvalue As String)
Public Property Variable() As String
Get
Variable = mValue
End Get
Set(ByVal value As String)
mValue = value
RaiseEvent VariableChanged(mValue)
End Set
End Property
End Class
Module BrowserExec
Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Integer
Public Sub LaunchNewBrowser(ByVal strUrl As String)
Try
'CREATE SOME VARIABLES
Dim BrowserExec As String = New String(" "c, 255)
Dim FileName As String
Dim RetVal As Long
Dim FileNumber As Integer
Dim SWriter As StreamWriter
'CREATE A TEMP HTM FILE SO WE CAN FIND OUT WHAT BROWSER IS
'THE DEFAULT ONE ON THE SYSTEM
FileName = Application.StartupPath & "\temp.htm"
SWriter = File.CreateText(FileName)
SWriter.Write("<html></html>")
SWriter.Close()
'CALL THE API TO FIND THE EXE ASSOCIATED WITH HTM FILES
RetVal = FindExecutable(FileName, vbNullString, BrowserExec)
BrowserExec = BrowserExec.Trim
'IF WE GET ONE, LAUNCH THE URL IN THE NEW INSTANCE OF THE BROWSER
If RetVal <= 32 Or BrowserExec = String.Empty Then
MessageBox.Show("Could not find a valid web browser")
Else
Process.Start(BrowserExec, strUrl)
End If
'DELETE THAT PESKY TEMP FILE
File.Delete(FileName)
Catch ex As Exception
'IF ANYTHING GOES WRONG, LET PEOPLE KNOW WHO'S FAULT IT IS
MessageBox.Show("An error has occured cause kleinma obviously can't write good code" & ControlChars.CrLf & ex.Message)
End Try
End Sub
End Module
https://sites.google.com/site/amerigoware/Home/Tabbed%20Browser.zip?attredirects=0&d=1[^]
|