Public Class Form4

    Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub detectclor(ByVal x As Integer, ByVal y As Integer)



        Dim bmpimage As New Bitmap(PictureBox1.ImageLocation)


        PictureBox1.Visible = True

        PictureBox1.Image = bmpimage


        Dim pixel = bmpimage.GetPixel(x, y)


        Dim r As Integer = pixel.R
        Dim g As Integer = pixel.G
        Dim b As Integer = pixel.B

        If Form1.CheckBox2.Checked = True Then

            Dim textsynthesiser As New System.Speech.Synthesis.SpeechSynthesizer



            textsynthesiser.SpeakAsync(" Current Color Is " & "Color: RGB : " & r & " " & g & " " & b)




        End If
        Label1.Text = " RGB VALUE FOR SELECTED PIXEL : " & r & " " & g & " " & b

        Form1.Label3.Text = "Color: RGB : " & r & " " & g & " " & b


        Dim text As String = "Lamp Color changed to pixel's RGB value (" & r & " " & g & " " & b & ")" & " on Day : " & Today.Date & "  Hour : " & TimeOfDay.Hour - 12 & " Minute : " & TimeOfDay.Minute & vbNewLine


        System.IO.File.AppendAllText(My.Application.Info.DirectoryPath & "\ledlog.txt", vbNewLine & text)

        Form1.SerialPort1.Write(9)
        Form1.SerialPort1.Write(r & "," & g & "," & b)








    End Sub

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

    End Sub

    Private Sub PictureBox1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseClick
        detectclor(e.X, e.Y)
    End Sub
End Class