How can I get Mouse Position?

Please support our VB.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Reply

Join Date: Sep 2004
Posts: 2
Reputation: vbpro is an unknown quantity at this point 
Solved Threads: 0
vbpro vbpro is offline Offline
Newbie Poster

How can I get Mouse Position?

 
0
  #1
Sep 28th, 2004
How can I get the Mouse Position from the mousemove event inthe VB.net?

I can't find out how to do this.. :rolleyes:
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 2
Reputation: Mr.Stupid is an unknown quantity at this point 
Solved Threads: 0
Mr.Stupid Mr.Stupid is offline Offline
Newbie Poster

Re: How can I get Mouse Position?

 
0
  #2
Oct 18th, 2004
Originally Posted by vbpro
How can I get the Mouse Position from the mousemove event inthe VB.net?

I can't find out how to do this.. :rolleyes:


  1. Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
  2.  
  3. Label1.Text = "X." & e.X & vbCrLf & "Y." & e.Y
  4.  
  5. End Sub
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1
Reputation: Benuz is an unknown quantity at this point 
Solved Threads: 0
Benuz Benuz is offline Offline
Newbie Poster

Re: How can I get Mouse Position?

 
0
  #3
Jul 5th, 2007
Originally Posted by Mr.Stupid View Post
  1. Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
  2.  
  3. Label1.Text = "X." & e.X & vbCrLf & "Y." & e.Y
  4.  
  5. End Sub
hi,
but these code above only works inside the form.

how to get the mouse coordinates / position by using VB2005.NET in anywhere?
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 21
Reputation: iTaChi is an unknown quantity at this point 
Solved Threads: 2
iTaChi's Avatar
iTaChi iTaChi is offline Offline
Newbie Poster

Re: How can I get Mouse Position?

 
0
  #4
Jul 16th, 2007
you cant get the coordinates of the pointer outside the form..

if you wish to.. customize windows!! :lol:
"If you understand, you can learn anything"


http://www.cprogrammingdock.serverspeople.net
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,007
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 513
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: How can I get Mouse Position?

 
0
  #5
Jul 16th, 2007
you would need to use DirectX or something for that
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,070
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 124
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic

Re: How can I get Mouse Position?

 
0
  #6
Jul 19th, 2007
do you want to trap mouse co-ordinates any where on the screen ?
Share your Knowledge.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,007
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 513
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: How can I get Mouse Position?

 
0
  #7
Jul 19th, 2007
yes
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 1
Reputation: Skullmagic is an unknown quantity at this point 
Solved Threads: 0
Skullmagic's Avatar
Skullmagic Skullmagic is offline Offline
Newbie Poster

Re: How can I get Mouse Position?

 
2
  #8
Jul 25th, 2007
  1. Dim MyPointAPI As POINTAPI
  2. Private Type POINTAPI
  3. X As Long
  4. Y As Long
  5. End Type
  6.  
  7. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
  8.  
  9. Public Sub Timer1_Timer()
  10. l = GetCursorPos(MyPointAPI)
  11. Label1.Caption = CStr(MyPointAPI.X) & ", " & CStr(MyPointAPI.Y)
  12. End Sub
Last edited by Skullmagic; Jul 25th, 2007 at 5:38 am. Reason: Don't look good!!!
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 24
Reputation: blondie.simon is an unknown quantity at this point 
Solved Threads: 0
blondie.simon blondie.simon is offline Offline
Newbie Poster

Re: How can I get Mouse Position?

 
1
  #9
Jul 25th, 2007
I have not been using VB for very long but this is how I have been getting the mouse postion on the screen.

  1. Dim MousePosition As Point
  2. MousePosition = Cursor.Position

I hope this helps
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 2
Reputation: WarMacre is an unknown quantity at this point 
Solved Threads: 0
WarMacre WarMacre is offline Offline
Newbie Poster

Re: How can I get Mouse Position?

 
0
  #10
Feb 20th, 2009
I know this thread is old, but I'm confused as to why so many people think this impossible, at least without using an API.

blondie.simon was on the right tracks.

Here's how:

  1. dim mousePos as point = me.mouseposition
  2.  
  3. dim mousePosX as integer = form1.mouseposition.x
  4. dim mousePosY as integer = form1.mouseposition.y

Simples see!

And to capture the location when the mouse is moving:

  1. Private Sub mouseMove_Capture(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles _
  2. MyBase.MouseMove
  3. Dim mousePos As point= Me.MousePosition
  4. End Sub
Note, that the above only functions when the mouse is not over any other form object, but the form itself. It is possible to only capture the mouse movement within a single object too, like a label or picture box for example.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC