Click here to Skip to main content
15,886,788 members
Articles / Programming Languages / Visual Basic

Pocket PC Simulated Resizable Browser

Rate me:
Please Sign up or sign in to vote.
4.10/5 (4 votes)
18 Jan 2008CPOL3 min read 42.7K   860   23  
A mini browser for PDA web developers.
Public Class Form1

    Dim stack As New Stack(Of String)
    Dim lastUrl As String = ""
    Dim confirmClosed As Boolean = False
    Dim FavoriteLinksCollection As New Collections.Specialized.StringCollection
    Dim favoriteDisplayCollection As New Collections.Specialized.StringCollection

    
   
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadSettings()
        ComboBox1.Text = My.Settings.strHomePage
        If strHomeUrl <> "" Then
            ComboBox1.Text = strHomeUrl.Replace("""", "")
        End If
        If ComboBox1.Text <> "" Then
            Go(ComboBox1.Text)
        End If
    End Sub

#Region "Menu Action"
    Private Sub VerticalLayoutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VerticalLayoutToolStripMenuItem.Click
        V_Layout()
    End Sub

    Private Sub HorizontalLayoutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HorizontalLayoutToolStripMenuItem.Click
        H_Layout()
    End Sub

    Private Sub QuitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuitToolStripMenuItem.Click
        Me.Close()
    End Sub
#End Region

#Region "Click Events"
    Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
        Me.Cursor = Cursors.WaitCursor
        Go(ComboBox1.Text)
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub picBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picBack.Click
        'Back()
        WebBrowser1.GoBack()
    End Sub

    Private Sub picRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picRefresh.Click
        WebBrowser1.Refresh()
    End Sub

    Private Sub picHome_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picHome.Click
        Go(txtHomePage.Text)
    End Sub

    Private Sub picFavorite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picFavorite.Click
        'Go(txtFavoritePage.Text)
        BuildFavoritePanel()
    End Sub
    Private Sub btnSaveDefault_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        SaveSettings()
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        confirmClosed = True
        Me.Close()
    End Sub
#End Region

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        ComboBox1.Text = WebBrowser1.Url.ToString
    End Sub

    Private Sub Go(ByVal strUrl As String)
        Try
            If Not ComboBox1.Items.Contains(strUrl) Then
                ComboBox1.Items.Add(strUrl)
            End If
            If lastUrl <> strUrl Then
                lastUrl = strUrl
                stack.Push(strUrl)
            End If
            If Not strUrl.ToUpper.StartsWith("HTTP://") Then
                strUrl = "http://" & strUrl
            End If
            WebBrowser1.Url = New Uri(strUrl)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
        End Try
    End Sub

    Private Sub Back()
        If stack.Count > 0 Then
            lastUrl = stack.Pop
            If stack.Count > 0 Then
                lastUrl = stack.Pop
            End If
            ComboBox1.Text = lastUrl
            Go(lastUrl)
        End If
    End Sub

    Private Sub LoadSettings()
        txtHomePage.Text = My.Settings.strHomePage
        'txtFavoritePage.Text = My.Settings.strFavoritePage
        If My.Settings.FavoriteLinks IsNot Nothing Then
            FavoriteLinksCollection = My.Settings.FavoriteLinks
            favoriteDisplayCollection = My.Settings.FavoriteDisplays
        End If

    End Sub

    Private Sub SaveSettings()
        My.Settings.strHomePage = txtHomePage.Text
        'My.Settings.strFavoritePage = txtFavoritePage.Text
        My.Settings.FavoriteLinks = FavoriteLinksCollection
        My.Settings.FavoriteDisplays = favoriteDisplayCollection
        My.Settings.Save()
        'MsgBox("New Settings Saved")
    End Sub

  

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Panel1.Visible = True

        If confirmClosed = True Then
            e.Cancel = False
        Else
            e.Cancel = True
        End If

    End Sub

    Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        SaveSettings()
    End Sub

    Private Sub WebBrowser1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles WebBrowser1.GotFocus, btnGo.GotFocus, ComboBox1.GotFocus
        PanelFavorite.Visible = False
    End Sub


#Region "Favorite Implementation"

    Private Sub BuildFavoritePanel()
        Dim i As Integer = favoriteDisplayCollection.Count
        PanelFavorite.Location = New System.Drawing.Point(Fx, Fy - (i - 1) * 12)
        PanelFavorite.Height = 22 + 12 * i

        For k As Integer = 1 To 3
            LinkLabelF(k, "")
        Next
        For k As Integer = 1 To i
            LinkLabelF(k, favoriteDisplayCollection.Item(k - 1))
        Next

        PanelFavorite.Visible = True
    End Sub


    Private Sub LinkLabelAddFavorite_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabelAddFavorite.LinkClicked
        Dim s As String = ""
        s = InputBox("Add Favorite Display Name")
        If s <> "" Then
            If favoriteDisplayCollection.Count < 3 Then
                favoriteDisplayCollection.Add(s)
                FavoriteLinksCollection.Add(ComboBox1.Text)
                Dim i As Integer = favoriteDisplayCollection.Count
                LinkLabelF(i, favoriteDisplayCollection.Item(i - 1))
            End If
        End If
        BuildFavoritePanel()
    End Sub

    Private Sub LinkLabelF(ByVal item As Integer, ByVal Text As String)
        Select Case item
            Case 1
                LinkLabelF1.Text = Text
                If Text = "" Then
                    picDeleteF1.Visible = False
                Else
                    picDeleteF1.Visible = True
                End If
            Case 2
                LinkLabelF2.Text = Text
                If Text = "" Then
                    picDeleteF2.Visible = False
                Else
                    picDeleteF2.Visible = True
                End If
            Case 3
                LinkLabelF3.Text = Text
                If Text = "" Then
                    picDeleteF3.Visible = False
                Else
                    picDeleteF3.Visible = True
                End If
        End Select
    End Sub


    Private Sub LinkLabelF1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabelF1.LinkClicked
        Go(FavoriteLinksCollection.Item(0))
        PanelFavorite.Visible = False
    End Sub

    Private Sub LinkLabelF2_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabelF2.LinkClicked
        Go(FavoriteLinksCollection.Item(1))
        PanelFavorite.Visible = False
    End Sub

    Private Sub LinkLabelF3_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabelF3.LinkClicked
        Go(FavoriteLinksCollection.Item(2))
        PanelFavorite.Visible = False
    End Sub

    Private Sub picDeleteF1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picDeleteF1.Click
        RemoveFavorite(0)

    End Sub

    Private Sub picDeleteF2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picDeleteF2.Click
        RemoveFavorite(1)
    End Sub

    Private Sub picDeleteF3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picDeleteF3.Click
        RemoveFavorite(2)
    End Sub

    Private Sub RemoveFavorite(ByVal index As Integer)
        favoriteDisplayCollection.RemoveAt(index)
        FavoriteLinksCollection.RemoveAt(index)
        BuildFavoritePanel()
    End Sub


#End Region

    Private Sub CustomerizeSizeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CustomerizeSizeToolStripMenuItem.Click
        Dim f As New Form2(ComboBox1.Text)
        f.Show()

    End Sub

    Public ReadOnly Property HomePage() As String
        Get
            Return txtHomePage.Text
        End Get
    End Property
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder Bisware Technology Limited
Hong Kong Hong Kong
I am an IT consultant and software developer based in Hong Kong.

Please click here to see my blog and my company at biswaretech.com

Comments and Discussions