Public Class Form_Monitor

    Public AP_RA As String
    Public AP_DEC As String

    Private Sub ButtonUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonUpdate.Click
        Form1.ScopePositionToolStripMenuItem.PerformClick()

    End Sub

    Private Sub ButtonGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonGo.Click
        Form1.ButtonRADEC.PerformClick()
        Try
            Form_RA_DEC.RAh.Value = Mid(AP_RA, 1, 2)
            Form_RA_DEC.RAm.Value = Mid(AP_RA, 4, 2)
            Form_RA_DEC.RAs.Value = Mid(AP_RA, 7, 2)
            Form_RA_DEC.RAss.Value = Mid(AP_RA, 10, 1)
            If Mid(AP_DEC, 1, 1) = "+" Then
                Form_RA_DEC.DECplus.Checked = True
            Else
                Form_RA_DEC.DECminus.Checked = True
            End If
            Form_RA_DEC.DECd.Value = Mid(AP_DEC, 2, 2)
            Form_RA_DEC.DECm.Value = Mid(AP_DEC, 5, 2)
            Form_RA_DEC.DECs.Value = Mid(AP_DEC, 8, 2)

        Catch ex As Exception
            If Form1.ErrorMsgBox = True Then
                Dim M As String
                M = ex.Message & vbCrLf & "RA = " & AP_RA & vbCrLf & "DEC = " & AP_DEC
                MsgBox(M, MsgBoxStyle.OkOnly, "Set RA/DEC Error")
            End If
            Form1.StatusLabel.Text = "Set Ra/Dec failed"
        End Try

    End Sub

    Private Sub Form_Monitor_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Form1.MonitorW = Me.Width
        Form1.MonitorH = Me.Height

    End Sub

    Private Sub Form_Monitor_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' Make sure form is on the screen
        If Me.Location.X < 0 Or Me.Location.Y < 0 Then
            Me.Location = New Point(0, 0)
        End If

        ' 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
        ToolTip1.SetToolTip(ButtonMonitor, "Monitor inactive, click to start")

    End Sub

    Private Sub ButtonMonitor_Click(sender As System.Object, e As System.EventArgs) Handles ButtonMonitor.Click
        If TimerMonitor.Enabled = False Then
            TimerMonitor.Enabled = True
            ButtonMonitor.ForeColor = Color.DarkGreen
            ToolTip1.SetToolTip(ButtonMonitor, "Monitor active, click to stop")
        Else
            TimerMonitor.Enabled = False
            ButtonMonitor.ForeColor = Color.DarkRed
            ToolTip1.SetToolTip(ButtonMonitor, "Monitor inactive, click to start")
        End If

    End Sub

    Private Sub TimerMonitor_Tick(sender As System.Object, e As System.EventArgs) Handles TimerMonitor.Tick
        If Form1.SerialPort1.IsOpen = True Or Form1.SocketIsOpen = True Or Form1.IsConnected = True Then
            If Form_Dome.CheckBoxTrack.Enabled = False Then
                ButtonUpdate.PerformClick()
            End If
        End If

    End Sub
End Class