VB2005: is mouse CursorPosition still supported?

  • Thread starter Thread starter Slindee
  • Start date Start date
S

Slindee

This statement worked in VB2003, but generates an error for
'CursorPosition' in VB2005. Did not find anything in Help.

mouseX = CursorPosition.X - Me.Location.X
 
Slindee said:
This statement worked in VB2003, but generates an error for
'CursorPosition' in VB2005. Did not find anything in Help.

mouseX = CursorPosition.X - Me.Location.X

I believe you wanted to type 'Cursor.Position', which is supported in both
..NET 1.0 and .NET 2.0.
 
How about this:

Private Sub Form2_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
Dim pt As Point = System.Windows.Forms.Cursor.Position
Dim strScreenPosition As String = pt.ToString
Dim strClientPosition As String =
Me.PointToClient(pt).ToString
Me.Text = "Screen: " & strScreenPosition & ", Client: " &
strClientPosition
End Sub

Works for me.

/Joergen Bech
 
Control.MousePosition and Cursor.Position do exactly the same thing:
Make a call to GetCursorPos in user32.dll.

But Control.MousePosition is a read-only property, whereas
Cursor.Position is read/write (write using SetCursorPos in user32.dll)
so for consistency I always use Cursor.Position.

Regards,

Joergen Bech
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top