Mouse position rgb color?

Discussion in 'Programming General' started by kharg0, Feb 17, 2008.

Mouse position rgb color?
  1. Unread #1 - Feb 17, 2008 at 3:05 PM
  2. kharg0
    Joined:
    Feb 25, 2007
    Posts:
    131
    Referrals:
    0
    Sythe Gold:
    0

    kharg0 Active Member

    Mouse position rgb color?

    I changed my code a lot so heres the new 1:

    Code:
        Private Function findColor(ByVal Color As Color, ByVal Area As Rectangle) As Point
            Dim AreaSize As Size = Area.Size
            Dim TempBitmap As New Bitmap(AreaSize.Width, AreaSize.Height)
            Graphics.FromImage(TempBitmap).CopyFromScreen(Area.Location, New Point(), AreaSize)
            For x As Integer = 0 To Area.Height - 1
                For y As Integer = 0 To Area.Width - 1
                    If TempBitmap.GetPixel(x, y) = Color Then Return New Point(Area.X + x, Area.Y + y)
                Next
            Next
            Return New Point(-1, -1)
        End Function
    
        Private Sub Startbuttn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start.Click
            Timer1.Start()
            Do Until MousePosition.X = Screen.PrimaryScreen.Bounds.X
                If PictureBox2.BackColor = PictureBox1.BackColor Then
    
                Else
                    Cursor.Position = New Point(MousePosition.X + 1, MousePosition.Y)
                End If
            Loop
            If MousePosition.X = Screen.PrimaryScreen.Bounds.X Then
                Cursor.Position = New Point(MousePosition.X - Screen.PrimaryScreen.Bounds.Width, MousePosition.Y + 1)
            End If
            If MousePosition.Y = Screen.PrimaryScreen.Bounds.Y Then
                MsgBox("No location was found for your chosen color")
            End If
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Dim TempBitmap As New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
            Graphics.FromImage(TempBitmap).CopyFromScreen(Screen.PrimaryScreen.Bounds.Location, New Point(), Screen.PrimaryScreen.Bounds.Size)
            PictureBox2.BackColor = TempBitmap.GetPixel(System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y)
        End Sub
    
        Private Sub Choosebuttn_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Choose.MouseUp
            Dim TempBitmap As New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
            Graphics.FromImage(TempBitmap).CopyFromScreen(Screen.PrimaryScreen.Bounds.Location, New Point(), Screen.PrimaryScreen.Bounds.Size)
            PictureBox1.BackColor = TempBitmap.GetPixel(System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y)
        End Sub
     
< My client for RuneScape | Force mouse click? >

Users viewing this thread
1 guest


 
 
Adblock breaks this site