Cursor Location / Title Bar height

  • Thread starter Thread starter Strahimir Antoljak
  • Start date Start date
S

Strahimir Antoljak

I want to track the cursor location relative to a control on the form. I am
aware of System.Windows.Forms.Cursor.Position which provides absolute cursor
position relative to the screen. With right subtractions of the form
location and the control location it is possible to get the relative cursor
location to the screen.... with one exception - form has a title bar, and
border widths which I do not know the values of. Is there a way to find out
the title bar width and border widths? preferably programmatically? thanks
 
Strahimir Antoljak said:
I want to track the cursor location relative to a control on the
form. I am aware of System.Windows.Forms.Cursor.Position
which provides absolute cursor position relative to the screen.
With right subtractions of the form location and the control location
it is possible to get the relative cursor location to the screen....

Take a look at the properties of the 'SystemInformation' class and the
form's/control's 'PointToClient' and 'PointToScreen' methods.
 
Maybe the PointToClient method can help you,
or maybe this piece of code,
place a label and a button on a form, call the label lblMouse and copy paste
the following code

<<<<<<<<code>>>>>>>>>
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
lblMouse.Text = "X: " & e.X & " Y: " & e.Y
lblMouse.Refresh()
End Sub

Private Sub Button1_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseMove
lblMouse.Text = "X: " & e.X & " Y: " & e.Y
lblMouse.Refresh()
End Sub

<<<<<<<<<code>>>>>>>>>>

hth
Peter
 
Herfried,

exactly what I needed. thanks for the quick and 'to the point' replay
 
Peter,

exactly what I needed. Thanks a bunch

--
Strah @ Langan

Peter Proost said:
Maybe the PointToClient method can help you,
or maybe this piece of code,
place a label and a button on a form, call the label lblMouse and copy
paste
the following code

<<<<<<<<code>>>>>>>>>
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
lblMouse.Text = "X: " & e.X & " Y: " & e.Y
lblMouse.Refresh()
End Sub

Private Sub Button1_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseMove
lblMouse.Text = "X: " & e.X & " Y: " & e.Y
lblMouse.Refresh()
End Sub

<<<<<<<<<code>>>>>>>>>>

hth
Peter
 

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