Getting the mouse_down / mouse_up coordinates

  • Thread starter Dino M. Buljubasic
  • Start date
D

Dino M. Buljubasic

I am trying to get coordinates of mouse_down/mouse_up event BUT relevant to
the form or the parent of a control, not to the control where mouse click
has occured. That means, even if I click a control on the form, I want to
get the coordinates of the form of the click event, not coordinates of the
control that was clicked on.

My user controls are on a panel pnToday. Each user control has two text
boxes inside representing whole and half hour (e.g. 11:00 am and 11:30am)
Currently I am doint it as:

' add event handler to all dynamically loaded user controls
AddHandler ctype(MyUserControl.TextBox1, TextBox).MouseDown, AddressOf
pnToday_MouseDown
AddHandler ctype(MyUserControl.TextBox2, TextBox).MouseDown, AddressOf
pnToday_MouseDown
AddHandler ctype(MyUserControl.TextBox1, TextBox).MouseUp, AddressOf
pnToday_MouseUp
AddHandler ctype(MyUserControl.TextBox2, TextBox).MouseUp, AddressOf
pnToday_MouseUp

' then in my mouse down / up events for the panel (parent of user controls)
Private Sub pnToday_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles pnToday.MouseDown
ptEntryPoint = New Point(e.X, e.Y)
EntryTextBox = Me.GetChildAtPoint(ptEntryPoint)
'MsgBox(EntryTextBox.GetType.ToString) ' this should retrun type of
control clicked but it returns type of my toolbar
End Sub

Private Sub pnToday_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles pnToday.MouseUp
ptExitPoint = New Point(e.X, e.Y)

ExitTextBox = Me.GetChildAtPoint(ptExitPoint)

MsgBox("Entry at (" & ptEntryPoint.X & " ; " & ptEntryPoint.Y & ")"
& vbCrLf & _
"Exit at (" & ptExitPoint.X & " ; " & ptExitPoint.Y & ")")

MsgBox("Entry Hour: " & CType(EntryTextBox, TextBox).Tag & " " &
" Exit Hour: " & CType(ExitTextBox, TextBox).Tag) ' this crashes because of
invalid type conversion from toolbar to textbox, because the point returned
is not relevant to parent container of user controls.
End Sub

Regards,
Dino
 
H

Herfried K. Wagner [MVP]

* "Dino M. Buljubasic said:
I am trying to get coordinates of mouse_down/mouse_up event BUT relevant to
the form or the parent of a control, not to the control where mouse click
has occured. That means, even if I click a control on the form, I want to
get the coordinates of the form of the click event, not coordinates of the
control that was clicked on.

You will have to work with the controls' or form's 'PointToClient' and
'PointToScreen' methods.
 

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

Top