467,146 Members | 1,180 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,146 developers. It's quick & easy.

Getting the mouse_down / mouse_up coordinates

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

--
-------------------------------------------------------------------------
FIGHT BACK AGAINST SPAM!
Download Spam Inspector, the Award Winning Anti-Spam Filter
http://mail.giantcompany.com

Nov 20 '05 #1
  • viewed: 1809
Share:
1 Reply
* "Dino M. Buljubasic" <di*************@rivusglobal.com> scripsit:
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.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Tim Bücker | last post: by
6 posts views Thread by Seth Illgard | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.