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

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
 
R

rowe_newsgroups

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
 
S

sagar

hi seth

sorry for late reply

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

thanks
sagar
 
R

rowe_newsgroups

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
 
R

rowe_newsgroups

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
 

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