943,400 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 105660
  • VB.NET RSS
You are currently viewing page 1 of this multi-page discussion thread
Sep 28th, 2004
0

How can I get Mouse Position?

Expand Post »
How can I get the Mouse Position from the mousemove event inthe VB.net?

I can't find out how to do this.. :rolleyes:
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vbpro is offline Offline
2 posts
since Sep 2004
Oct 18th, 2004
0

Re: How can I get Mouse Position?

Quote 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:


VB.NET Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Mr.Stupid is offline Offline
2 posts
since Oct 2004
Jul 5th, 2007
0

Re: How can I get Mouse Position?

Click to Expand / Collapse  Quote originally posted by Mr.Stupid ...
VB.NET Syntax (Toggle Plain Text)
  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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Benuz is offline Offline
1 posts
since Jul 2007
Jul 16th, 2007
0

Re: How can I get Mouse Position?

you cant get the coordinates of the pointer outside the form..

if you wish to.. customize windows!! :lol:
Reputation Points: 29
Solved Threads: 2
Newbie Poster
iTaChi is offline Offline
21 posts
since Mar 2007
Jul 16th, 2007
0

Re: How can I get Mouse Position?

you would need to use DirectX or something for that
Moderator
Featured Poster
Reputation Points: 1764
Solved Threads: 574
Moderator
jbennet is offline Offline
16,485 posts
since Apr 2005
Jul 19th, 2007
0

Re: How can I get Mouse Position?

do you want to trap mouse co-ordinates any where on the screen ?
Featured Poster
Reputation Points: 665
Solved Threads: 427
Posting Genius
debasisdas is online now Online
6,406 posts
since Feb 2007
Jul 19th, 2007
0

Re: How can I get Mouse Position?

yes
Moderator
Featured Poster
Reputation Points: 1764
Solved Threads: 574
Moderator
jbennet is offline Offline
16,485 posts
since Apr 2005
Jul 25th, 2007
3

Re: How can I get Mouse Position?

VB.NET Syntax (Toggle Plain Text)
  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!!!
Reputation Points: 14
Solved Threads: 0
Newbie Poster
Skullmagic is offline Offline
1 posts
since Jul 2007
Jul 25th, 2007
2

Re: How can I get Mouse Position?

I have not been using VB for very long but this is how I have been getting the mouse postion on the screen.

VB.NET Syntax (Toggle Plain Text)
  1. Dim MousePosition As Point
  2. MousePosition = Cursor.Position

I hope this helps
Reputation Points: 34
Solved Threads: 0
Light Poster
blondie.simon is offline Offline
27 posts
since Jul 2007
Feb 20th, 2009
0

Re: How can I get Mouse Position?

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:

VB.NET Syntax (Toggle Plain Text)
  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:

VB.NET Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
WarMacre is offline Offline
2 posts
since Feb 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Iteration using the Do-Loop
Next Thread in VB.NET Forum Timeline: Directory copying?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC