⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 downloadplugindialog.vb

📁 一个界面很好的iRadio收音机 一个界面很好的iRadio收音机
💻 VB
字号:
Option Explicit On
Option Strict On
Option Compare Text

Imports System.Xml
Imports System.Xml.XPath
Imports System.Text
Imports System.IO
Imports System.Windows.Forms

''' <copyright>Copyright ?2006 Herbert N Swearengen III</copyright>
'''
''' <notice>
''' This application maybe freely distributed and modified as long
''' as the copyright notice and EULA are retained. This applies to
''' both the compiled application and it's source code.
''' </notice>
Public Class DownloadPlugInDialog

#Region " Form-Level Variables "

    ''' <summary>
    ''' Collections to hold information from PlugInList.xml.
    ''' </summary>
    Private PlugInName As New Collection
    Private PlugInDescription As New Collection
    Private PlugInUri As New Collection
    Private PlugInImage As New Collection

    ''' <summary>
    ''' Selected index of cboPlugIn.
    ''' </summary>
    Private plugInIndex As Integer

#End Region

#Region " Form Events "

    Private Sub DownloadPlugInDialog_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim i As Integer

        ' Set color.
        SetColor(Me, Settings.Color)

        ' Clear all collections.
        If PlugInName IsNot Nothing Then
            PlugInName.Clear()
        End If

        If PlugInDescription IsNot Nothing Then
            PlugInDescription.Clear()
        End If

        If PlugInUri IsNot Nothing Then
            PlugInUri.Clear()
        End If

        If PlugInImage IsNot Nothing Then
            PlugInImage.Clear()
        End If

        ' Read PlugInList file.
        ReadPlugInList()

        ' Populate combobox and select first item.
        If PlugInName.Count > 0 Then
            For i = 1 To PlugInName.Count
                cboPlugIn.Items.Add(PlugInName(i))
            Next

            ' Select first item.
            cboPlugIn.SelectedIndex = 1

        End If

    End Sub

    Private Sub DownloadPlugInDialog_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.Escape Then
            DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub

#End Region

#Region " pnlHeader Mouse Events - Move Form "

    ''' <summary>
    ''' Responds to the left mouse button down on pnlHeader.
    ''' For each movement, the form is moved correspondingly.
    ''' </summary>
    Private Sub pnlHeader_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles pnlHeader.MouseDown

        ' If the left mouse is pressed, release form for movement
        If e.Button = Windows.Forms.MouseButtons.Left Then
            ReleaseCapture()
            SendMessage(Handle, WM_NCLBUTTONDOWN, CType(HTCAPTION, UIntPtr), CType(0, UIntPtr))
        End If
    End Sub

#End Region

#Region " Button Events "

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
    End Sub

    Private Sub btnOK_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnOK.MouseDown
        btnOK.FlatAppearance.BorderColor = Color.DodgerBlue
    End Sub

    Private Sub btnOK_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnOK.MouseUp
        btnOK.FlatAppearance.BorderColor = Color.Black
    End Sub

    Private Sub btnOK_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.MouseEnter
        btnOK.FlatAppearance.BorderColor = Color.DarkOrange
    End Sub

    Private Sub btnOK_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.MouseLeave
        btnOK.FlatAppearance.BorderColor = Color.Black
    End Sub

#End Region

#Region " ComboBox Events "

    Private Sub cboPlugIn_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboPlugIn.SelectedIndexChanged
        If PlugInName.Count > 0 Then
            plugInIndex = cboPlugIn.SelectedIndex + 1   ' Collections are one-based, cboIndex is zero-based.

            ' Display description.
            txtDescription.Text = PlugInDescription.Item(plugInIndex).ToString

            ' Display image.
            picPlugIn.BackgroundImage = CType(My.Resources.ResourceManager.GetObject(PlugInImage.Item(plugInIndex).ToString), Image)

            ' Set download uri by storing it in the picturebox tag property.
            picPlugIn.Tag = PlugInUri(plugInIndex).ToString

        End If

    End Sub

#End Region

#Region " PictureBox Events "

    Private Sub picClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picClose.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
    End Sub

    Private Sub picClose_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles picClose.MouseEnter
        picClose.Image = My.Resources.Close_Mouse_Hover
    End Sub

    Private Sub picClose_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles picClose.MouseLeave
        picClose.Image = My.Resources.Close_Mouse_Up
    End Sub

    Private Sub picPlugIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picPlugIn.Click

        Try
            ' Open browser to PlugIn download site.
            Dim startInfo As New ProcessStartInfo(picPlugIn.Tag.ToString)
            Process.Start(startInfo)
        Catch ex As NullReferenceException
            ' No uri information is available, just quit.
            Exit Try
        Catch exc As Net.WebException
            MessageBox.Show("The PlugIn web site could not be reached. You may want to check " & _
                "your Internet connection or your browser settings.", My.Application.Info.Title, _
                MessageBoxButtons.OK, MessageBoxIcon.Stop)
        End Try

    End Sub

#End Region

#Region " XML Methods "
    ''' <summary>
    ''' Read XML file into collections.
    ''' </summary>
    Private Sub ReadPlugInList()
        Dim filePath As String = My.Application.Info.DirectoryPath & "\PlugInList.xml"
        Dim query As String
        Dim myXPNIterator As XPathNodeIterator

        Try
            Dim myXMLDocument As New XPathDocument(filePath)
            Dim myNavigator As XPathNavigator = myXMLDocument.CreateNavigator()

            ' Add <name> to collection.
            query = "descendant::name"
            myXPNIterator = myNavigator.Select(query)

            Do While myXPNIterator.MoveNext()
                PlugInName.Add(myXPNIterator.Current.Value)
            Loop

            ' Add <description> to collection.
            query = "descendant::description"
            myXPNIterator = myNavigator.Select(query)

            Do While myXPNIterator.MoveNext
                PlugInDescription.Add(myXPNIterator.Current.Value)
            Loop

            ' Add <uri> to collection.
            query = "descendant::uri"
            myXPNIterator = myNavigator.Select(query)

            Do While myXPNIterator.MoveNext
                PlugInUri.Add(myXPNIterator.Current.Value)
            Loop

            ' Add <image> to collection.
            query = "descendant::image"
            myXPNIterator = myNavigator.Select(query)

            Do While myXPNIterator.MoveNext
                PlugInImage.Add(myXPNIterator.Current.Value)
            Loop

        Catch ex As FileNotFoundException
            MessageBox.Show("The plugin list file:" & vbCrLf & filePath & vbCrLf & _
                            "was not found. Please restore this file or reinstall the program.", _
                            My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Catch exc As IOException
            MessageBox.Show("An error occurred reading the plugin list file""" & Path.GetFileName(filePath) & """." & vbCrLf & _
                            "The system returned the following information:" & vbCrLf & exc.Message, _
                            My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Catch excep As XPathException
            MessageBox.Show("An error has occurred in ""ReadPlugInList"", the system returned the following information:" & _
                vbCrLf & excep.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Catch except As XmlException
            MessageBox.Show("An error has occurred in ""ReadPlugInList"", the system returned the following information:" & _
                vbCrLf & except.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Sub

#End Region

End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -