how do I get the cursor position in relation to a specified control?
Printable View
how do I get the cursor position in relation to a specified control?
VB Code:
MousePosition.X and MousePosition.Y
Almost surely, Pirate gave you what you needed, but if you wanted to know where the blinking cursor is, for example, in a textbox:
Dim goofy As Byte = Me.TextBox1.SelectionStart
Excuse me for my english!
that gives it to me relative to the screen dosn't it pirate? what if I want it in relation to a listview, for example?
Then use PointToClient function to get coordinates within client area (not in the whole screen)
like this
VB Code:
Dim pnt As Point = Me.ListView1.PointToClient(New Point(MousePosition.X, MousePosition.Y)) MessageBox.Show(pnt.ToString)
You might need to check the difference between the previous code and this one . Here we used the form's PointToClient function not the control's .
VB Code:
Dim pnt2 As Point = Me.PointToClient(New Point(MousePosition.X, MousePosition.Y))
yeah, thanks pirate.
pointToClient is the way to go.
-marvin