Public Class Form1
    Inherits System.Windows.Forms.Form

    ' members...
    Private _selectedFavorite As WebFavorite


#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    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

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents lnkUrl As System.Windows.Forms.LinkLabel
    Friend WithEvents lstFavorites As System.Windows.Forms.ListView
    Friend WithEvents hdrName As System.Windows.Forms.ColumnHeader
    Friend WithEvents hdrUrl As System.Windows.Forms.ColumnHeader
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.lnkUrl = New System.Windows.Forms.LinkLabel()
        Me.lstFavorites = New System.Windows.Forms.ListView()
        Me.hdrName = New System.Windows.Forms.ColumnHeader()
        Me.hdrUrl = New System.Windows.Forms.ColumnHeader()
        Me.SuspendLayout()
        '
        'lnkUrl
        '
        Me.lnkUrl.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.lnkUrl.Location = New System.Drawing.Point(8, 232)
        Me.lnkUrl.Name = "lnkUrl"
        Me.lnkUrl.Size = New System.Drawing.Size(504, 23)
        Me.lnkUrl.TabIndex = 1
        Me.lnkUrl.TabStop = True
        Me.lnkUrl.Text = "LinkLabel1"
        Me.lnkUrl.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'lstFavorites
        '
        Me.lstFavorites.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.lstFavorites.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.hdrName, Me.hdrUrl})
        Me.lstFavorites.Location = New System.Drawing.Point(8, 8)
        Me.lstFavorites.Name = "lstFavorites"
        Me.lstFavorites.Size = New System.Drawing.Size(504, 216)
        Me.lstFavorites.TabIndex = 2
        Me.lstFavorites.View = System.Windows.Forms.View.Details
        '
        'hdrName
        '
        Me.hdrName.Text = "Name"
        Me.hdrName.Width = 250
        '
        'hdrUrl
        '
        Me.hdrUrl.Text = "URL"
        Me.hdrUrl.Width = 250
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(520, 261)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lstFavorites, Me.lnkUrl})
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        ' create a favorites object...
        Dim favorites As New Favorites()
        favorites.ScanFavorites()

        ' go through each favorite...
        Dim favorite As WebFavorite
        For Each favorite In favorites.Favorites

            ' add it to the list...
            Dim item As New WebFavoriteListViewItem(favorite)
            lstFavorites.Items.Add(item)

            ' if this is the first item, select it...
            If lstFavorites.Items.Count = 1 Then

                ' select it...
                item.Selected = True
                SelectedFavorite = favorite

            End If

        Next
    End Sub


    ' SelectedFavorite property...
    Public Property SelectedFavorite() As WebFavorite
        Get
            Return _SelectedFavorite
        End Get
        Set(ByVal Value As WebFavorite)

            ' store the item...
            _SelectedFavorite = Value

            ' did we select anything?
            If Not _SelectedFavorite Is Nothing Then

                ' update the link label control...
                lnkUrl.Text = "Visit " & _SelectedFavorite.Name
                lnkUrl.Enabled = True
            Else
                ' disable the link...
                lnkUrl.Enabled = False

            End If

        End Set
    End Property


    Private Sub lstFavorites_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstFavorites.Click
        ' reset the selection...
        SelectedFavorite = Nothing

        ' go through each item looking for the selected one...
        Dim item As WebFavoriteListViewItem
        For Each item In lstFavorites.Items

            ' selected?
            If item.Selected = True Then

                ' store the selected item...
                SelectedFavorite = item.Favorite

                ' exit the loop...
                Exit For

            End If

        Next
    End Sub


    Private Sub lnkUrl_LinkClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkUrl.LinkClicked
        ' do we have a selection?
        If Not SelectedFavorite Is Nothing Then

            ' show it...
            SelectedFavorite.Open()

        End If
    End Sub


End Class
