Hi Andy,
sorry for annoying you :) but I have a problem that I can not solve and was
hoping you could help me with that.
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
"_Andy_" <wi******@nospamthanks.gov> wrote in message
news:0p********************************@4ax.com...
On Thu, 27 Nov 2003 18:36:49 GMT, "Dino M. Buljubasic"
<di*************@rivusglobal.com> wrote:
Hi Andy,
thanks for reading this post and for your reply. The only thing I don't
understand is how to redirect mouse move event to another control. Can
youexplain me that?
Thank you,
Dino
By "redirection" I simply meant the act of calling the handler of
another instance of the class (instead of this one itself). It's taken
care of by the "If ctrl Is Me Then" line. The logic is this:
If the mouse pointer is within the rectangle of this control
Handle the event
Else
Find the control that is under the pointer
Call the handler of that control instead
End If
What I did fail to mention is the use of "Form.GetChildAtPoint()" to
determine which control the mouse is over.
hth