The normal behavior of almost any GUI per click on one of the controllers is to call an Event for this control. If in one place there are several controls, the event is called only for the "top".

Tell me, please, is it possible to learn about all such "hits"? In my case, there is a Canvas with a bunch of child Ellipse'ov, which must respond to the click.

PS: I do not see any problems in order to calculate the intersection manually, but I would like to do without crutches :)

    4 answers 4

    Write your cursor collision detector with objects, it's simple. wiki / Ellipse to help.


    Use this object to get mouse coordinates. You may still need a linear conversion of coordinates from the coordinate system in which the ellipse is specified to the coordinate system in which the cursor is set or vice versa.

    • Thanks for the advice, thank you so much, but this is a bit wrong =) I can go over Child'am, go to one coordinate system and check the collision well, I can (initially it was done, only the collision was searched not with the ellipses themselves, but with the objects that they schematically depict), I would just like to use, if possible, standard tools. There is a possibility, for example, that inside standard containers, a certain partitioning of space is implemented in order to simplify the search from O (N) to some O (log N). Well, even if not, I still would not want to use crutches ... - allcreater 2:55 pm
    • If inside .NET a binary search tree is implemented for all form objects to trigger this event, and not just a dumb search of the coordinates of all form objects, all that remains is to shake hands with them. private void button1_Click (object sender, EventArgs e) - igumnov

    Since you have WPF in tags, read about Routed Events, and about their types - ascending and descending. That's what you need.

      WPF always generates a click for an element on top only - it is not treated. But you can solve your problem like this: make a list in which all the ellipses that the mouse is over are stored. In the event handler for the MouseEnter ellipse, add it to the list, and in MouseLeave, delete it. These are just two lines. And in the click on any ellipse without dancing with coordinates, use this list.

        Found such a thing ( VisualTreeHelper.HitTest ), the results are positive. I found, unfortunately, on my own, but still HUGE thanks to everyone for their attention and advice!

        Hit Testing in the Visual Layer .