⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmmain.vb

📁 VB.NET的Web浏览器IE7的克隆选项卡式浏览器 描述:这是一个例子写的vb.net浏览器使用的。 NET Framework 2.0 ( Visual Studio 2005中) 。这是一个
💻 VB
📖 第 1 页 / 共 3 页
字号:
'Working with the Visual Studio 2005 Browser control.
'Copyright 2007 - Thomas Maxwell.
'Example application showing working with the Webbrowser control in Visual Studio.
'You may freely distribute this code as long as you include credit to myself
'and to the author of the tab control (Eduardo Oliveira.)
'// Ruler User control code can only be redistributed with the copyright 
'text intact.
'//
Imports System.IO
Imports System.Runtime.InteropServices
Imports System.Drawing
Imports System.Text
Public Class frmMain
#Region " API "
    'This is an API call to get the icon of a favorite.
    Private Structure SHFILEINFO
        Public hIcon As IntPtr            ' : icon
        Public iIcon As Integer           ' : icondex
        Public dwAttributes As Integer    ' : SFGAO_ flags
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
        Public szDisplayName As String
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _
        Public szTypeName As String
    End Structure

    Private Declare Auto Function SHGetFileInfo Lib "shell32.dll" _
            (ByVal pszPath As String, _
             ByVal dwFileAttributes As Integer, _
             ByRef psfi As SHFILEINFO, _
             ByVal cbFileInfo As Integer, _
             ByVal uFlags As Integer) As IntPtr

    Private Const SHGFI_ICON = &H100
    Private Const SHGFI_SMALLICON = &H1
    Private Const SHGFI_LARGEICON = &H0    ' Large icon
    Private nIndex
#End Region

    Private CurSearchURL As String
    Private CurSearchTitle
    Private fitm As ToolStripMenuItem

#Region " FORM "

    Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If Not IsNothing(AppManager.CurrentBrowser) Then
            AppManager.CurrentBrowser.Dispose()
        End If

        Dim oControl As Control
        For Each oControl In Me.Controls
            oControl.Dispose()
        Next
    End Sub

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AppManager.MainForm = Me
        Dim ofrm As New frmBrowser
        Dim oTab As New Ie7Clone.TabPage(ofrm)
        Me.tc1.TabPages.Add(oTab.Form)

        'Set the 1st tab to non closeable, just like ie 7
        tc1.TabPages(0).CloseButtonVisible = False
        If AppManager.StartURL = "" Then
            'Do we show the start page or have the browser go home?
            If My.Settings.UseStartPage = True Then
                ofrm.wb.DocumentText = My.Resources.StartPage
            Else
                ofrm.wb.GoHome()
            End If
        Else
            ofrm.wb.Navigate(AppManager.StartURL)
        End If

        LoadFavorites()
        LoadSearchProviders()
    End Sub

    Private Sub LoadHistory()
        '
    End Sub

#End Region

#Region " Favorites Loading Code "
    'In most custom browser implementations you will probably want to 
    'have your own favorite storage information, storing fav icons in your own cache
    'or in a database. You may also want to implement a custom import / export wizard. 
    'Since favorites are just text files simular to .ini files, for this example
    'we'll just load them the quickest way by loading the path and during the 
    'onclick in the handler open the file and direct the browser to the url. 

    Private Sub LoadFavorites()
        Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.Favorites)
        tvFavs.BeginUpdate()
        ' Clear the Favorites list
        tvFavs.Nodes.Clear()
        ' Load favorites from all sub-directories
        LoadFolders(New System.IO.DirectoryInfo(Path), Nothing, Nothing)
        ' Load the favorites from the favorites folder
        LoadPath(Path, Nothing, Nothing)
        'Now lets load the links toobar
        'LoadLinkFolders(New System.IO.DirectoryInfo(Path & "\Links\"), Nothing)
        ' LoadLinksPath(Path & "\Links\", Nothing)
        ' Repaint the TreeView
        tvFavs.EndUpdate()
    End Sub

    Private Sub LoadFolders(ByVal dirInfo As System.IO.DirectoryInfo, _
    ByVal currentNode As TreeNode, ByVal oitm As ToolStripMenuItem)

        Dim objNode As System.Windows.Forms.TreeNode
        Dim fitm As ToolStripMenuItem

        Dim objDir As System.IO.DirectoryInfo

        For Each objDir In dirInfo.GetDirectories()
            If currentNode Is Nothing Then
                objNode = tvFavs.Nodes.Add(objDir.Name, objDir.Name, 0, 1)
                objNode.Tag = String.Empty
                fitm = mnuFavs.DropDownItems.Add(objDir.Name)
                fitm.Image = My.Resources.folder3
            Else
                objNode = currentNode.Nodes.Add(objDir.Name, objDir.Name, 0, 1)
                objNode.Tag = String.Empty
                fitm = oitm.DropDownItems.Add(objDir.Name)
                fitm.Image = My.Resources.folder3
            End If
            ' Set the full path of the folder
            objNode.Tag = objDir.FullName
            fitm.Tag = objDir.FullName

            If objDir.GetDirectories().Length = 0 Then
                ' This node has no further sub-directories
                LoadPath(objDir.FullName, objNode, fitm)
            Else
                ' Add this folder to the current node and continue
                ' processing sub-directories.
                LoadFolders(objDir, objNode, fitm)
                LoadPath(objDir.FullName, objNode, fitm)
            End If
        Next objDir
    End Sub

    Private Sub LoadPath(ByVal strPath As String, _
    ByVal currentNode As TreeNode, ByVal mitm As ToolStripMenuItem)

        Dim oNode As TreeNode
        Dim oitm As ToolStripMenuItem
        Dim name As String
        Dim objDir As New System.IO.DirectoryInfo(strPath)
        Dim SmallIco As IntPtr
        Dim shinfo As SHFILEINFO
        shinfo = New SHFILEINFO
        ' Process each File in the path with a ".url" extension
        Dim objFile As System.IO.FileInfo
        For Each objFile In objDir.GetFiles("*.url")
            oNode = New TreeNode
            oitm = New ToolStripMenuItem
            '///////////////////////////////////////////////////
            'get the icon.
            'Note:
            'Here you could call the appmanager code to get the actual 
            'favorite icon from the site (will slow things down)...
            'If you decide to implement your own custom favorites
            'grab the fav icon and store it in an access db, xml file etc
            'either by path or ole object and save it locally.
            shinfo.szDisplayName = New String(Chr(0), 260)
            shinfo.szTypeName = New String(Chr(0), 80)
            'Get the small icon.
            SmallIco = SHGetFileInfo(objFile.FullName, 0, shinfo, _
                        Marshal.SizeOf(shinfo), _
                        SHGFI_ICON Or SHGFI_SMALLICON)
            '////////////////////////////////////////////////////
            ' Set the Text property to the "Friendly" name
            name = Path.GetFileNameWithoutExtension(objFile.Name)
            Dim oIcon As Icon = System.Drawing.Icon.FromHandle(shinfo.hIcon)
            tvFavs.ImageList.Images.Add(name, oIcon.ToBitmap)
            oNode.Text = name
            oNode.Tag = objFile.FullName
            oNode.ImageKey = name
            oNode.SelectedImageKey = name
            If currentNode Is Nothing Then
                tvFavs.Nodes.Add(oNode)
                oitm.Text = name
                oitm.Image = oIcon.ToBitmap
                oitm.Tag = objFile.FullName
                mnuFavs.DropDownItems.Add(oitm)
                AddHandler oitm.Click, AddressOf HandleFav
                'AddHandler oitm.MouseDown, AddressOf HandleFavMouseDown
            Else
                currentNode.Nodes.Add(oNode)
                oitm.Text = name
                oitm.Image = oIcon.ToBitmap
                oitm.Tag = objFile.FullName
                mitm.DropDownItems.Add(oitm)
                AddHandler oitm.Click, AddressOf HandleFav
                'AddHandler oitm.MouseDown, AddressOf HandleFavMouseDown
            End If
        Next objFile
    End Sub


    Private Sub LoadLinkFolders(ByVal dirInfo As System.IO.DirectoryInfo, _
    ByVal oitm As ToolStripMenuItem)

        Dim fitm As ToolStripMenuItem
        Dim objDir As System.IO.DirectoryInfo

        For Each objDir In dirInfo.GetDirectories()
            fitm = New ToolStripMenuItem
            fitm.Text = objDir.Name
            fitm.Tag = ""
            fitm.Image = My.Resources.folder3
            If oitm Is Nothing Then
                tbLinks.Items.Add(fitm)
            Else
                fitm.Image = My.Resources.folder3
                oitm.DropDownItems.Add(fitm)
            End If

            If objDir.GetDirectories().Length = 0 Then
                ' This node has no further sub-directories
                LoadLinksPath(objDir.FullName, fitm)
            Else
                ' Add this folder to the current node and continue
                ' processing sub-directories.
                'LoadLinkFolders(objDir, fitm)
                LoadLinksPath(objDir.FullName, fitm)
            End If
        Next objDir
    End Sub

    Private Sub LoadLinksPath(ByVal strPath As String, _
    ByVal mitm As ToolStripMenuItem)

        Dim oitm As ToolStripMenuItem
        Dim name As String
        Dim objDir As New System.IO.DirectoryInfo(strPath)
        Dim SmallIco As IntPtr
        Dim shinfo As SHFILEINFO
        shinfo = New SHFILEINFO
        ' Process each URL in the path (URL files end with a ".url" extension
        Dim objFile As System.IO.FileInfo
        For Each objFile In objDir.GetFiles("*.url")
            oitm = New ToolStripMenuItem
            'get the icon.
            shinfo.szDisplayName = New String(Chr(0), 260)
            shinfo.szTypeName = New String(Chr(0), 80)
            'Get the small icon.
            SmallIco = SHGetFileInfo(objFile.FullName, 0, shinfo, _
                        Marshal.SizeOf(shinfo), _
                        SHGFI_ICON Or SHGFI_SMALLICON)
            ' Set the Text property to the "Friendly" name
            name = Path.GetFileNameWithoutExtension(objFile.Name)
            Dim oIcon As Icon = System.Drawing.Icon.FromHandle(shinfo.hIcon)

            If mitm Is Nothing Then
                oitm.Text = name
                oitm.Image = oIcon.ToBitmap
                oitm.Tag = objFile.FullName
                tbLinks.Items.Add(oitm)
                'AddHandler oitm.Click, AddressOf HandleFav
                AddHandler oitm.MouseDown, AddressOf HandleFavMouseDown
            Else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -