locked
FAQs: 如何创建自己的Web浏览器? RRS feed

答案

  • 我们通常使用已有的WebBrowser控件创建自己的Web浏览器,它提供了一些基本的导航功能。

     

    示例: 创建一个简单的Web浏览器.

    创建一个用作地址栏的TextBox控件,一个ToolStrip控件并往上添加一些菜单栏按钮,诸如转到后退前进停止刷新,等等。
     

    Public Class Form1

        ' “转到按钮

        Private Sub btnGo_Click(ByVal sender As System.Object, _

                            ByVal e As System.EventArgs) Handles btnGo.Click

            WebBrowser1.Navigate(txtURL.Text)

        End Sub

     

        ' 在地址栏中,按下回车跳转

        Private Sub txtURL_KeyDown(ByVal sender As Object, _

                           ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtURL.KeyDown

            If e.KeyData = Keys.Enter Then

                btnGo.PerformClick()

                e.SuppressKeyPress = True

            End If

        End Sub

     

        ' “后退按钮

        Private Sub tsBtnBack_Click(ByVal sender As System.Object, _

                           ByVal e As System.EventArgs) Handles tsBtnBack.Click

            If WebBrowser1.CanGoBack Then

                WebBrowser1.GoBack()

            End If

        End Sub

     

        ' “前进按钮

        Private Sub tsBtnForward_Click(ByVal sender As System.Object, _

                           ByVal e As System.EventArgs) Handles tsBtnForward.Click

            If WebBrowser1.CanGoForward Then

                WebBrowser1.GoForward()

            End If

        End Sub

     

        ' “停止按钮

        Private Sub tsBtnStop_Click(ByVal sender As System.Object, _

                           ByVal e As System.EventArgs) Handles tsBtnStop.Click

            WebBrowser1.Stop()

        End Sub

     

        ' “刷新按钮

        Private Sub tsRefreshNormal_Click(ByVal sender As System.Object, _

                           ByVal e As System.EventArgs) Handles tsRefreshNormal.Click

            WebBrowser1.Refresh()

        End Sub

     

        ' “主页按钮

        Private Sub tsBtnHome_Click(ByVal sender As System.Object, _

                           ByVal e As System.EventArgs) Handles tsBtnHome.Click

            WebBrowser1.GoHome()

        End Sub

     

        ' “查询按钮

        Private Sub tsBtnSearch_Click(ByVal sender As System.Object, _

                           ByVal e As System.EventArgs) Handles tsBtnSearch.Click

            WebBrowser1.GoSearch()

        End Sub

    End Class

     

    请访问这些链接来获取与此主题相关的一些详细案例:

    http://social.msdn.microsoft.com/forums/en-US/Vsexpressvb/thread/8ea89e24-c60b-4ce5-a0de-39217f15b1b8/

    http://social.msdn.microsoft.com/forums/en-US/vbide/thread/ec4b4255-9a87-4649-b297-cbcd83cbef86/


    如果您对我们的论坛在线支持服务有任何的意见或建议,请通过邮件告诉我们。
    MSDN 论坛好帮手 立刻免费下载  MSDN 论坛好帮手
    2011年3月2日 12:43