How can I know who color is under cursor (mouse) ???
Thanx !
Printable View
How can I know who color is under cursor (mouse) ???
Thanx !
Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Simple as that... Just add this API to your project and call with the appropraite varibles to recieve your RGB in long form.
VB Code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Label1.Caption = GetPixel(Form1.hdc, X / 15, Y / 15) End Sub
The 15 is the twips per pixel on my form. Screen.TwipsPerPixelX (Y) ...
Hope that this helps
NOMAD
If you don't want to "bother" with API you can just use the point function for Picture box or Form... This will only work when you are over a form or picture box... I think, I haven't tested it just remember looking into it.
NOMAD
To get it for the entirety of the screen, use this snippet that I've written.It requires the declaration of GetCursorPos, GetDesktopWindow, GetDc, and GetPixel. It also requires the PointAPI Type, all of which are included above the function.VB Code:
Private Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long Private Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long Private Declare Function GetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As Long Private Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long Private Type POINTAPI x As Long y As Long End Type Function ColourUnderCursor() As Long Dim lPoint As POINTAPI GetCursorPos lPoint ColourUnderCursor = GetPixel(GetDc(GetDesktopWindow), lPoint.x, lPoint.y) End Function
OK thanx fo this !! but i have a prblem !
I have 2 Picture box ( Picture1 and Picture 2) ..I need when i move mouse in Picture1 ...then Picture2.BackColor = ColourUnderCursor !!!!
How can I do this .... Thanx
Make a timer control and set it's refresh to, say, 50ms (the Interval property). In the timer subroutine, add this code:It's as simple as that!VB Code:
Picture2.BackColor = ColourUnderCursor