is there any way to find the position of mouse click on a form

  • Thread starter Thread starter sagar
  • Start date Start date
S

sagar

is there any way to find the position of mouse click on a form
actually the problem is i m having more than one controls on a form i
want to find which control is selected using mouse down

any help is fine for me

thanks
 
is there any way to find the position of mouse click on a form

Check the e.X and e.Y values generated by the form.mouseclick event.
want to find which control is selected

If you want "global" handler then you could do a recursive search for
controls on the form, and use addhandler to map the control.GotFocus()
event to the method you want to handle the gotfocus events. Let me know
if you need some code.

Thanks,

Seth Rowe
 
hi seth

sorry for late reply

i ll be very thankful to u if u provide me the code

thanks
sagar
 
Here you go - I wrote this in a hurry so be careful!

<pseudocode>

Private Sub MapControls(ByVal container As
Windows.Forms.Control.ControlCollection)
For Each c As Control In container
AddHandler c.MouseDown, AddressOf HandleMouseDown
If c.Controls.Count > 0 Then
MapControls(c.Controls)
End If
Next
End Sub

Private Sub HandleMouseDown(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.MouseEventArgs) Handles
ProductionName.MouseDown
MsgBox("X:" & e.X & " Y:" & e.Y)
End Sub

</pseudocode>

Thanks,

Seth Rowe
 
i m not able to figure out what is ProductionName

It's a textbox that lists the name of the Production Contact in the
project I was working on when you posted last! :-)

Anyways, just get rid of that entire handles statement - it shouldn't
be there. (at least I tagged the code as pseudocode). I just chose a
textbox on my form and selected the mouseclick event for in order to
autogenerate the code. Sorry about that!

Thanks,

Seth Rowe
 
Back
Top