Imports System.Net
Imports System.IO
Public Class browser
Dim AktiverBrowser As WebBrowser
Dim imlist As ImageList = New ImageList()
Dim b1 As Integer = 0
Dim bmpW As Integer = 16
Dim bmpH As Integer = 16
Dim coordBmp As New Point(20, 8)
'Le bitmap devono avere esattamente le dimensioni bmpW e bmpH !
Dim bmpFocusOn As Bitmap
Dim bmpFocusOff As Bitmap
Dim bmpHover As Bitmap
'Font per ridisegno Titoli TabControl
Private tcFont As New Font("Calibri", 14, FontStyle.Regular, GraphicsUnit.Pixel)
Private titoloTPB As Brush = New SolidBrush(Color.Black)
Private Sub back_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles back.MouseDown
back.BackgroundImage = My.Resources.back1
End Sub
Private Sub back_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles back.MouseUp
back.BackgroundImage = My.Resources.back
End Sub
Private Sub back_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles back.MouseLeave
back.BackgroundImage = My.Resources.back
End Sub
Private Sub forward_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles forward.MouseDown
forward.BackgroundImage = My.Resources.forward1
End Sub
Private Sub forward_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles forward.MouseUp
forward.BackgroundImage = My.Resources.forward
End Sub
Private Sub forward_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles forward.MouseLeave
forward.BackgroundImage = My.Resources.forward
End Sub
Private Sub browser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
bmpFocusOn = New Bitmap(imlTabClose.Images(0))
bmpFocusOff = New Bitmap(imlTabClose.Images(1))
bmpHover = New Bitmap(imlTabClose.Images(2))
resizeForm()
TabControl1.Font = tcFont
addTab()
AddHandler TabControl1.DrawItem, AddressOf RidisegnaTC
TabControl1.TabPages(0).ForeColor = Color.LightSeaGreen
CType(TabControl1.SelectedTab.Controls(0), WebBrowser).Navigate("http://www.google.de")
End Sub
Sub addTab()
Dim Browser As New WebBrowser
Dim newTab As New TabPage("Neuer Tab")
'Aggiungo degli spazi dopo
newTab.Text = newTab.Text.PadRight(55, " ")
TabControl1.TabPages.Insert(TabControl1.TabCount - 1, newTab)
Browser.Name = "FA Explorer"
Browser.Dock = DockStyle.Fill
'per non visualizzare i messaggi di errore
Browser.ScriptErrorsSuppressed = True
TabControl1.SelectTab(TabControl1.TabCount - 2)
TabControl1.SelectedTab.Controls.Add(Browser)
CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate("")
AddHandler Browser.DocumentCompleted, AddressOf Done
End Sub
Sub resizeForm()
TabControl1.Width = Me.ClientSize.Width
TabControl1.Height = Me.ClientSize.Height - TabControl1.Location.Y
End Sub
Private Sub RidisegnaTC(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs)
Dim R As Rectangle = TabControl1.GetTabRect(e.Index) 'la linguetta della scheda
Dim titoloTP As String = TabControl1.TabPages(e.Index).Text 'titolo scheda
Dim brush As Drawing2D.LinearGradientBrush
'Disegno lo sfondo delle linguette
If e.State = DrawItemState.Selected Then
brush = New Drawing2D.LinearGradientBrush(R, Color.White, Color.LightBlue, Drawing2D.LinearGradientMode.Vertical)
e.Graphics.FillRectangle(brush, R)
Else
brush = New Drawing2D.LinearGradientBrush(R, Color.White, Color.LightSeaGreen, Drawing2D.LinearGradientMode.Vertical)
e.Graphics.FillRectangle(brush, R)
End If
'Disegno Titoli
e.Graphics.DrawString(titoloTP, tcFont, titoloTPB, New PointF(R.X + 22, R.Y + 5))
If e.Index < TabControl1.TabCount - 1 Then
'Disegno la favicon
If TabControl1.TabPages(e.Index).ImageKey <> "" Then
Dim tabIcon As New Bitmap(imlTabIcon.Images(TabControl1.TabPages(e.Index).ImageKey))
e.Graphics.DrawImage(tabIcon, New Point(R.X + 1, R.Y + 1))
End If
'Disegno Bmp Chiusura
If TabControl1.TabCount > 2 Then
If e.State = DrawItemState.Selected Then
e.Graphics.DrawImage(bmpFocusOn, New Point(R.X + R.Width - coordBmp.X, coordBmp.Y))
End If
End If
End If
End Sub
Private Sub TabControl1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TabControl1.MouseClick
Dim iTab As Integer
Dim R As Rectangle = TabControl1.GetTabRect(TabControl1.SelectedIndex)
Dim rectBmp As New Rectangle(New Point(R.X + R.Width - coordBmp.X, coordBmp.Y), New Size(bmpW, bmpH))
If TabControl1.TabCount > 2 And rectBmp.Contains(e.Location) Then
iTab = TabControl1.SelectedIndex
TabControl1.TabPages.RemoveAt(iTab)
'seleziona la scheda precendente (solo se la scheda che è stata chiusa non è la prima)
If iTab > 0 Then TabControl1.SelectedIndex = iTab - 1
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CType(TabControl1.SelectedTab.Controls(0), WebBrowser).Navigate(urlboxBox1.Text)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End Sub
Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
If TabControl1.TabCount > 4 Then
If TabControl1.SelectedTab Is TabControl1.TabPages(0) Then ' Text (Beschriftung) auf dem Karteireiter
' Focus auf TextBox5 (liegt innerhalb von TabPage2)
End If
End If
If TabControl1.SelectedIndex = TabControl1.TabCount - 1 Then
addTab()
Else
If TabControl1.SelectedTab.Controls.Count > 0 Then
cambioScheda(TabControl1.SelectedTab)
urlboxBox1.Text = CType(TabControl1.SelectedTab.Controls(0), WebBrowser).Url.ToString
End If
End If
End Sub
Public Sub cambioScheda(ByVal tabscheda As TabPage)
Dim wb As WebBrowser
wb = CType(tabscheda.Controls(0), WebBrowser)
If wb.DocumentTitle <> "" Then
Me.Text = wb.DocumentTitle & " - " & "FA Explorer"
Else
Me.Text = "FA Explorer"
End If
urlboxBox1.Text = wb.Url.ToString
back.Enabled = wb.CanGoBack
forward.Enabled = wb.CanGoForward
End Sub
Private Sub Done(ByVal sender As Object, ByVal e As Windows.Forms.WebBrowserDocumentCompletedEventArgs)
Dim wb1 As WebBrowser
Dim linkTags As HtmlElementCollection
Dim linkType As String 'se è 'shortcut icon' o 'stylesheet', ecc.
Dim iconURL As String = ""
Dim fav As Image
Dim imgKey As String = "terra.png"
urlboxBox1.Text = CType(TabControl1.SelectedTab.Controls(0), WebBrowser).Url.ToString
wb1 = CType(sender, WebBrowser)
If CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle <> "" Then
Me.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle & " - " & "FA Explorer"
If Len(wb1.DocumentTitle.ToString) > 35 Then
wb1.Parent.Text = Strings.Left(wb1.DocumentTitle, 33) & "... "
Else
wb1.Parent.Text = wb1.DocumentTitle
End If
wb1.Parent.Text = wb1.Parent.Text.PadRight(55, " ")
Else
Me.Text = "FA Explorer"
wb1.Parent.Text = "Neuer Tab".PadRight(55, " ")
End If
End Sub
Private Sub urlboxBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles urlboxBox1.KeyDown
If e.KeyCode = Keys.Enter Then
CType(TabControl1.SelectedTab.Controls(0), WebBrowser).Navigate(urlboxBox1.Text)
End If
End Sub
Private Sub TabControl1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TabControl1.MouseMove
Dim R As Rectangle = TabControl1.GetTabRect(TabControl1.SelectedIndex)
Dim rectBmp As New Rectangle(New Point(R.X + R.Width - coordBmp.X, coordBmp.Y), New Size(bmpW, bmpH))
If TabControl1.TabCount > 2 Then
If rectBmp.Contains(e.Location) Then
TabControl1.CreateGraphics.DrawImage(bmpHover, New Point(R.X + R.Width - coordBmp.X, coordBmp.Y))
Else
TabControl1.CreateGraphics.DrawImage(bmpFocusOn, New Point(R.X + R.Width - coordBmp.X, coordBmp.Y))
End If
End If
End Sub
End Class