Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / COM / November 2004



Tip: Looking for answers? Try searching our database.

Coordinates of a pixel in a Picture

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Srikanth Ganesan - 18 Nov 2004 23:55 GMT
Hi,
I am a beginner to VB. I am trying to do the following:
I have a picture control with a GIF image in it. I want to be able to
store the coordinates of the pixels where the mousepointer points on the
image when I press a Key on the keyboard.

I tried using the Picture.MouseMove control. But the problem is that it
reports the Button/Shift event only when the mousepointer is moved. If I
just keep the pointer stationary, then the Button/Shift does not update.

Is it possible that I can call say the KeyDown event inside a MouseMove
event ? Please let me kno. Thanks

Srikanth
Dave - 19 Nov 2004 08:05 GMT
> Hi,
> I am a beginner to VB. I am trying to do the following:
[quoted text clipped - 10 lines]
>
> Srikanth

Why don't you store the X,Y points from MouseMove in module level variables
mX, mY.  You could refer to them from the KeyDown event.

Dave
Mark Alexander Bertenshaw - 21 Nov 2004 17:50 GMT
> Hi,
> I am a beginner to VB. I am trying to do the following:
[quoted text clipped - 11 lines]
>
> Srikanth

Srikanth -

Your best bet is to use a couple of API functions: GetCursorPos() to get the
cursor position, ScreenToClient() to convert screen coordinates to the
containing window coordinates, and then you would need to negatively offset
by the position of the graphic in the window.  You can get all the
definitions from Win.tlb or by using the declarations in the code below:
(note that I am using an Image control to hold the graphic).

-------------------------------------------------

Option Explicit

Private Type POINT
   X As Long
   Y As Long
End Type

Private Declare Function ScreenToClient Lib "User32.dll" ( _
   ByVal hWnd As Long, _
   ByRef udtPoint As POINT _
) As Long

Private Declare Function GetCursorPos Lib "User32.dll" ( _
   ByRef udtPoint As POINT _
) As Long

Private Function GetPixelInPicture(ByRef frm As Form, ByVal sngPicOffsetX As
Single, ByVal sngPicOffsetY As Single, ByRef lPixelX As Long, ByRef lPixelY
As Long)
Dim lPicOffsetX                     As Long
Dim lPicOffsetY                     As Long
Dim udtPoint                        As POINT

   lPicOffsetX = frm.ScaleX(sngPicOffsetX, frm.ScaleMode, vbPixels)
   lPicOffsetY = frm.ScaleY(sngPicOffsetY, frm.ScaleMode, vbPixels)

   GetCursorPos udtPoint
   ScreenToClient frm.hWnd, udtPoint

   lPixelX = udtPoint.X - lPicOffsetX
   lPixelY = udtPoint.Y - lPicOffsetY

End Function

Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Dim lPixelX As Long
Dim lPixelY As Long

   GetPixelInPicture Me, Image1.Left, Image1.Top, lPixelX, lPixelY
   MsgBox CStr(lPixelX) & " - " & CStr(lPixelY)

End Sub

-------------------------------------------------

--
Mark Bertenshaw
LEAX Controls Ltd.
UK
Srikanth Ganesan - 22 Nov 2004 18:07 GMT
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.