VB.NET写的一个简易WEB浏览器

虽然现在改学C#,可是对VB还是很怀念

写得很简单`,那时候是刚接触.NET语言``就选择了VB.NET

暑假实训的时候,组长让我们写了个浏览器小程序`学会了读取XML 保存XML

还有就是`一些新手常遇到的问题`

(虽然现在组长不在学校了`可我还是想对他说`谢谢你`!~)

我刚弄博客,传不来文件所以提供下面代码

以下是代码`大家可以参考下`

Imports System.Xml

Imports System.Xml.XPath

Public Class Form1

Inherits System.Windows.Forms.Form

Dim x As String

Dim b, pp As String

Dim lujin As String = Application.StartupPath

Dim file_Name As String

Dim xia As String

#Region " Windows 窗体设计器生成的代码 "

Public Sub New()

MyBase.New()

'该调用是 Windows 窗体设计器所必需的。

InitializeComponent()

'在 InitializeComponent() 调用之后添加任何初始化

End Sub

'窗体重写 dispose 以清理组件列表。

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Windows 窗体设计器所必需的

Private components As System.ComponentModel.IContainer

'注意: 以下过程是 Windows 窗体设计器所必需的

'可以使用 Windows 窗体设计器修改此过程。

'不要使用代码编辑器修改它。

Friend WithEvents AxWebBrowser1 As AxSHDocVw.AxWebBrowser

Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox

Friend WithEvents Button3 As System.Windows.Forms.Button

Friend WithEvents ToolBar1 As System.Windows.Forms.ToolBar

Friend WithEvents ToolBarButton1 As System.Windows.Forms.ToolBarButton

Friend WithEvents ToolBarButton2 As System.Windows.Forms.ToolBarButton

Friend WithEvents ToolBarButton3 As System.Windows.Forms.ToolBarButton

Friend WithEvents ToolBarButton4 As System.Windows.Forms.ToolBarButton

Friend WithEvents ToolBarButton5 As System.Windows.Forms.ToolBarButton

Friend WithEvents XTree1 As X.XTree

Friend WithEvents ToolBarButton6 As System.Windows.Forms.ToolBarButton

Friend WithEvents ToolBarButton7 As System.Windows.Forms.ToolBarButton

Friend WithEvents TextBox1 As System.Windows.Forms.TextBox

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))

Me.AxWebBrowser1 = New AxSHDocVw.AxWebBrowser

Me.ComboBox1 = New System.Windows.Forms.ComboBox

Me.Button3 = New System.Windows.Forms.Button

Me.ToolBar1 = New System.Windows.Forms.ToolBar

Me.ToolBarButton1 = New System.Windows.Forms.ToolBarButton

Me.ToolBarButton2 = New System.Windows.Forms.ToolBarButton

Me.ToolBarButton3 = New System.Windows.Forms.ToolBarButton

Me.ToolBarButton4 = New System.Windows.Forms.ToolBarButton

Me.ToolBarButton5 = New System.Windows.Forms.ToolBarButton

Me.ToolBarButton6 = New System.Windows.Forms.ToolBarButton

Me.ToolBarButton7 = New System.Windows.Forms.ToolBarButton

Me.XTree1 = New X.XTree

Me.TextBox1 = New System.Windows.Forms.TextBox

CType(Me.AxWebBrowser1, System.ComponentModel.ISupportInitialize).BeginInit()

Me.SuspendLayout()

'

'AxWebBrowser1

'

Me.AxWebBrowser1.AllowDrop = True

Me.AxWebBrowser1.Enabled = True

Me.AxWebBrowser1.Location = New System.Drawing.Point(0, 96)

Me.AxWebBrowser1.OcxState = CType(resources.GetObject("AxWebBrowser1.OcxState"), System.Windows.Forms.AxHost.State)

Me.AxWebBrowser1.Size = New System.Drawing.Size(1024, 768)

Me.AxWebBrowser1.TabIndex = 0

'

'ComboBox1

'

Me.ComboBox1.Location = New System.Drawing.Point(0, 56)

Me.ComboBox1.Name = "ComboBox1"

Me.ComboBox1.Size = New System.Drawing.Size(368, 20)

Me.ComboBox1.TabIndex = 3

'

'Button3

'

Me.Button3.Location = New System.Drawing.Point(384, 48)

Me.Button3.Name = "Button3"

Me.Button3.Size = New System.Drawing.Size(88, 32)

Me.Button3.TabIndex = 4

Me.Button3.Text = "转到"

'

'ToolBar1

'

Me.ToolBar1.AllowDrop = True

Me.ToolBar1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D

Me.ToolBar1.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.ToolBarButton1, Me.ToolBarButton2, Me.ToolBarButton3, Me.ToolBarButton4, Me.ToolBarButton5, Me.ToolBarButton6, Me.ToolBarButton7})

Me.ToolBar1.DropDownArrows = True

Me.ToolBar1.Location = New System.Drawing.Point(0, 0)

Me.ToolBar1.Name = "ToolBar1"

Me.ToolBar1.ShowToolTips = True

Me.ToolBar1.Size = New System.Drawing.Size(744, 43)

Me.ToolBar1.TabIndex = 5

'

'ToolBarButton1

'

Me.ToolBarButton1.Text = "前进"

'

'ToolBarButton2

'

Me.ToolBarButton2.Text = "后退"

'

'ToolBarButton3

'

Me.ToolBarButton3.Text = "收藏URL"

'

'ToolBarButton4

'

Me.ToolBarButton4.Text = "打开URL"

'

'ToolBarButton5

'

Me.ToolBarButton5.Text = "接收URL"

'

'ToolBarButton6

'

Me.ToolBarButton6.Text = "上一条"

'

'ToolBarButton7

'

Me.ToolBarButton7.Text = "下一条"

'

'XTree1

'

Me.XTree1.Location = New System.Drawing.Point(544, 16)

Me.XTree1.Name = "XTree1"

Me.XTree1.Size = New System.Drawing.Size(0, 0)

Me.XTree1.TabIndex = 6

'

'TextBox1

'

Me.TextBox1.Location = New System.Drawing.Point(0, 96)

Me.TextBox1.Multiline = True

Me.TextBox1.Name = "TextBox1"

Me.TextBox1.Size = New System.Drawing.Size(192, 128)

Me.TextBox1.TabIndex = 7

Me.TextBox1.Text = "TextBox1"

Me.TextBox1.Visible = False

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)

Me.ClientSize = New System.Drawing.Size(744, 370)

Me.Controls.Add(Me.TextBox1)

Me.Controls.Add(Me.XTree1)

Me.Controls.Add(Me.ToolBar1)

Me.Controls.Add(Me.ComboBox1)

Me.Controls.Add(Me.Button3)

Me.Controls.Add(Me.AxWebBrowser1)

Me.Name = "Form1"

CType(Me.AxWebBrowser1, System.ComponentModel.ISupportInitialize).EndInit()

Me.ResumeLayout(False)

End Sub

#End Region

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

x = ComboBox1.Text

AxWebBrowser1.Navigate(x)

ComboBox1.Items.Add(ComboBox1.Text)

pp = ComboBox1.Text

b = b & "<" & "yyy url=" & " '" & pp & " '" & "/>"

End Sub

Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick

Select Case e.Button.Text

Case "收藏URL"

Dim YY As String

Dim bb As New XmlDocument

bb.LoadXml("<YY>" & b & "</YY>")

bb.Save("F:\gongjing001\WindowsApplication2\bin\www.xml")

MsgBox("收藏成功")

Case "打开URL"

ComboBox1.Items.Clear()

file_Name = lujin & "\www.xml"

XTree1.XTree_Cmd("load_xml_file", file_Name, "*//peer", "Root", "") '显示树

XTree1.XTree_Cmd("walk_tree", "", "", "root", "") '遍历树

ComboBox1.Text = ""

Case "接收URL"

file_Name = lujin & "\www.xml"

XTree1.XTree_Cmd("load_xml_file", file_Name, "*//peer", "Root", "")

XTree1.XTree_Cmd("walk_tree", "", "", "root", "")

Case "上一条"

Try

ComboBox1.SelectedIndex = ComboBox1.SelectedIndex - 1

Catch ex As Exception

End Try

Case "下一条"

Try

ComboBox1.SelectedIndex = ComboBox1.SelectedIndex + 1

Catch ex As Exception

End Try

Case "前进"

Try

AxWebBrowser1.GoForward()

Catch ex As Exception

End Try

Case "后退"

Try

AxWebBrowser1.GoBack()

Catch ex As Exception

End Try

End Select

End Sub

Private Sub AxWebBrowser1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxWebBrowser1.Enter

End Sub

Private Sub XTree1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles XTree1.Click

End Sub

Private Sub XTree1_WalkTree(ByVal TPos As String, ByVal XPath As String, ByVal Xml As String, ByVal selNode As System.Windows.Forms.TreeNode) Handles XTree1.WalkTree

Dim m, n, b, c As String

m = selNode.Tag

n = Len(m)

b = n - 15

c = Mid(m, 11, b)

ComboBox1.Items.Add(c)

End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

'Dim com As ComboBox = CType(sender, ComboBox)

'Select Case com.SelectedItem

'End Select

AxWebBrowser1.Navigate(ComboBox1.Text)

End Sub

Private Sub AxWebBrowser1_NavigateComplete2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event) Handles AxWebBrowser1.NavigateComplete2

ComboBox1.Text = AxWebBrowser1.LocationURL

TextBox1.Text = Me.AxWebBrowser1.Document.GetType.FullName()

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

End Class