Well, this might not be the best way...
But with minor modifications the code you supplied below will work.
Attached is a sample form that is almost identical.
Take into consideration that LONG in VB6 = INTEGER in VB.Net.
There are other more elegant ways, but AFAIK until VB 2005 you still need
Win32API (GDI) to get access to the desktop graphics.
Make a form called "frmPixelColor"
Throw a Timer on it.
Paste this in.
'--------------------------------------------------
Private Structure POINTAPI
Public X As Integer
Public Y As Integer
End Structure
Private Declare Function GetCursorPos _
Lib "user32" (ByVal lpPoint As POINTAPI) As Integer
Private Declare Function GetDC _
Lib "user32" (ByVal hwnd As Integer) As Integer
Private Declare Function GetPixel _
Lib "gdi32" (ByVal hdc As Integer, _
ByVal X As Integer, ByVal Y As Integer) As Integer
Private Declare Function ReleaseDC _
Lib "user32" (ByVal hwnd As Integer, _
ByVal hdc As Integer) As Integer
Private lDesktopDC As Integer
Private Sub Timer1_Tick(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
Dim tPt As Point, lRGB As Integer
tPt = MousePosition
lRGB = GetPixel(lDesktopDC, tPt.X, tPt.Y)
If lRGB <> -1 Then
Me.BackColor = ColorTranslator.FromWin32(lRGB)
End If
End Sub
Private Sub frmPixelColor_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
lDesktopDC = GetDC(0)
Timer1.Interval = 100
Timer1.Enabled = True
End Sub
Private Sub frmPixelColor_Closed(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Closed
Call ReleaseDC(0, lDesktopDC)
End Sub
'--------------------------------------------------
See, the code is virtually identical.
Gerald
"Arthur" <te*****************************@yahoo.com> wrote in message
news:yNjfd.23987$%k.676@pd7tw2no...
Given the coordinates of a point on the screen (such as 185,185), how do
you get the color of said point using VB.NET 2003.
I have looked EVERYWHERE for this, but to no avail. All the examples I've
seen use old code that is no longer supported in .NET.
I will pay the first person who posts working code 10 bucks from paypal.
I'm desperate, and really want to know how to do this.
.Please don't post VB6 code or anything that contains the statements:
Private Type POINTAPI
X As Long
Y As Long
End Type
since TYPE is not supported in .NET 2003.
I got this code from experts exchange, but it doesn't work- it just keeps
giving me the same dozen digit number over and over again (which has no
meaning to me)
Private Structure POINTAPI
Public X As Long
Public Y As Long
End Structure
Private Declare Function GetCursorPos Lib "user32" (ByVal lpPoint As
POINTAPI) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As
Long Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long,
ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long,
ByVal hdc As Long) As Long
Private lDesktopDC As Long
Private Sub Form_Load()
lDesktopDC = GetDC(0)
Timer1.Interval = 100
Timer1.Enabled = True
End Sub
Private Sub Form_Unload(ByVal Cancel As Integer)
Call ReleaseDC(0, lDesktopDC)
End Sub
Private Sub Timer1_Timer()
Dim tPt As POINTAPI, lRGB As Long
Call GetCursorPos(tPt)
lRGB = GetPixel(lDesktopDC, tPt.X, tPt.Y)
If lRGB <> -1 Then
Me.BackColor = Color.FromArgb(cint(lRGB))
End If
End Sub
u can email me at @yahoo.com ( the first part reads SIRARTHUR1)