Click here to Skip to main content
15,891,828 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.8K   860   23  
A mini browser for PDA web developers.
Public Class Form2
    Dim stack As New Stack(Of String)
    Dim lastUrl As String = ""


    Public Sub New(ByVal url As String)
        InitializeComponent()
        ComboBox1.Items.Add(url)
        ComboBox1.SelectedIndex = 0
    End Sub
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Panel1.Visible = False
        InitializeBrowser(240, 320)
        LoadSelectCombo()
        Go(ComboBox1.SelectedText, False)
    End Sub

    Private Sub LoadSelectCombo()
        With cmbSelect
            .Items.Add("240x320")
            .Items.Add("160x240")
            .Items.Add("320x480")
            .Items.Add("320x240")
            .Items.Add("240x240")
            .Items.Add("480x240")
            .Items.Add("custom")

            .SelectedIndex = 0
        End With
    End Sub

    Private Sub InitializeBrowser(ByVal width As Integer, ByVal height As Integer)
        Dim margin As Integer = 10

        If width <= height Then
            'PictureBox1.Image = My.Resources.PDAFrame
            PictureBox1.Width = width + margin * 2
            PictureBox1.Height = height + margin * 15
            If PictureBox1.Width < Me.Width Then
                PictureBox1.Left = (Me.Width - PictureBox1.Width) / 2
            End If
            PanelHeader.Left = PictureBox1.Left + margin
            PanelHeader.Top = PictureBox1.Top + margin * 6

        Else
            'PictureBox1.Image = My.Resources.PDAFrame_h
            PictureBox1.Width = width + margin * 15
            PictureBox1.Height = height + margin * 2
            If PictureBox1.Width < Me.Width Then
                PictureBox1.Left = (Me.Width - PictureBox1.Width) / 2
            End If
            PanelHeader.Left = PictureBox1.Left + (margin * 15) / 2
            PanelHeader.Top = PictureBox1.Top + margin
        End If

        PanelHeader.Width = width

        ComboBox1.Left = PanelHeader.Left
        ComboBox1.Top = PanelHeader.Top + PanelHeader.Height
        ComboBox1.Width = width - btnGo.Width
        btnGo.Top = ComboBox1.Top
        btnGo.Left = ComboBox1.Left + ComboBox1.Width
        WebBrowser1.Width = width
        WebBrowser1.Height = height - PanelHeader.Height - ComboBox1.Height - PanelFooter.Height
        WebBrowser1.Left = PanelHeader.Left
        WebBrowser1.Top = ComboBox1.Top + ComboBox1.Height
        PanelFooter.Left = PanelHeader.Left
        PanelFooter.Width = width
        PanelFooter.Top = WebBrowser1.Top + WebBrowser1.Height
        If width <= height Then
            picButton_h.Visible = True
            picButton_h.Top = PanelFooter.Top + PanelFooter.Height + 10
            picButton_h.Left = PanelHeader.Left + (width - picButton_h.Width) / 2
            panelHole.Width = 3
            panelHole.Height = 25
            panelHole.Top = PictureBox1.Top + 20
            panelHole.Left = PanelHeader.Left + (width - panelHole.Width) / 2
            picEarPhone.Top = PictureBox1.Top + 25
            picEarPhone.Left = PanelHeader.Left + (width - picEarPhone.Width) / 2
            picButton_v.Visible = False
        Else
            picButton_h.Visible = False
            picButton_v.Top = PanelHeader.Top + (height - picButton_v.Height) / 2
            picButton_v.Left = WebBrowser1.Left + WebBrowser1.Width + 10
            panelHole.Width = 25
            panelHole.Height = 3
            panelHole.Top = PanelHeader.Top + (height - panelHole.Height) / 2
            panelHole.Left = PictureBox1.Left + 20
            picEarPhone.Top = PanelHeader.Top + (height - picEarPhone.Height) / 2
            picEarPhone.Left = PictureBox1.Left + 25

            picButton_v.Visible = True
        End If
        PanelBg.Width = PictureBox1.Width + 10
        PanelBg.Height = PictureBox1.Height + 10
        PanelBg.Left = PictureBox1.Left - 5
        PanelBg.Top = PictureBox1.Top - 5
        Me.Invalidate()
    End Sub


    Private Sub cmbSelect_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSelect.SelectedIndexChanged
        Try
            Panel1.Visible = False
            Dim strSelect As String = cmbSelect.SelectedItem.ToString
            If strSelect = "custom" Then
                Panel1.Visible = True
                Return
            End If
            Dim width, height As Integer
            width = CType(strSelect.Split("x"c)(0), Integer)
            height = CType(strSelect.Split("x"c)(1), Integer)

            InitializeBrowser(width, height)
            'WebBrowser1.Width = width
            'WebBrowser1.Height = height
        Catch ex As Exception
            MsgBox("Invalid Input", MsgBoxStyle.Exclamation)
        End Try
    End Sub

    Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
        Me.Cursor = Cursors.WaitCursor
        Go(ComboBox1.Text, True)
        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(Form1.HomePage, True)
    End Sub

    Private Sub Go(ByVal strUrl As String, ByVal withErrorMessage As Boolean)
        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
            If withErrorMessage Then
                MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            End If
        End Try
    End Sub

    Private Sub btnApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApply.Click
        Try
            Dim width, height As Integer
            width = CType(txtWidth.Text, Integer)
            height = CType(txtHeight.Text, Integer)
            If width < 100 OrElse width > 550 OrElse height < 100 OrElse width > 500 Then
                Throw New ApplicationException("Size out of range! Input number range is 100 to 550")
            End If
            InitializeBrowser(width, height)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
        End Try
    End Sub
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