Imports System.IO

Public Class Form_COM_PORTS

    Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        SetAsCom()

    End Sub

    Private Sub Form_COM_PORTS_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Me.Hide()

    End Sub

    Private Sub Form_COM_PORTS_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' Make sure window is not off of screen
        If Me.Left + Me.Width > Form1.ScreenWidth Then
            Me.Left = Form1.ScreenWidth - Me.Width - 100
        End If
        If Me.Top + Me.Height > Form1.ScreenHeight Then
            Me.Top = Form1.ScreenHeight - Me.Height - 100
        End If

    End Sub

    Private Sub ShowBluetoothMappingToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ShowBluetoothMappingToolStripMenuItem.Click
        Dim MyDoc As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\AP Mini Bluetooth Serial Devices.txt"
        Dim CmdLine As String = "Notepad " & MyDoc

        If File.Exists(MyDoc) = True Then
            Shell(CmdLine, AppWinStyle.NormalFocus, False)
        Else
            Form1.StatusLabel.Text = MyDoc & " Does not exist."
        End If

    End Sub

    Private Sub SetAsCOMPortToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SetAsCOMPortToolStripMenuItem.Click
        SetAsCom()

    End Sub

    Private Sub SetAsCom()
        Form1.ToolStripComboBoxCom.SelectedIndex = ListBox1.SelectedIndex

    End Sub
End Class