This project has moved and is read-only. For the latest updates, please go here.

Subsequent clicks on overlapping shapes

Dec 25, 2012 at 11:53 AM


When I perform subsequent clicks on overlapping shapes (in the same point) - shapes are selected one after another, e.g. A -> B -> C -> A -> and so on. This behavior is especially inconvenient (in my case) in case of a double click: when I double-click on the topmost shape A, in the double-click event handler I see that the selected shape is B - and this is not very good; besides, the "Model" PropertyGrid switches from A's model to B's model. As the result, I have to restore selection in the beginning of the double-click event handler:

public void OnMouseDoubleClick(MouseEventArgs e)
    if (_display.Diagram == null)
    Point pt = Point.Empty;
    _display.ControlToDiagram(e.Location, out pt);
    Shape shape = _display.Diagram.FindShape<MyShape>(pt);
    if (shape == null)
    _display.SelectShape(shape); // have to restore selected shape
    // do the main job now...

// Extension method:
public static Shape FindShape<T>(this Diagram diagram, Point pt)
    foreach (Shape shape in diagram.Shapes.TopDown)
        // NOTE: Help says that IShapeCollection "encapsulates a collection of
        // shapes sorted by z-order", so I do not check here that Z-Order = Top.
        if (shape is T && shape.ContainsPoint(pt.X, pt.Y))
            return shape;
    return null;

But even having restored the selected shape, I loose current expanded/collapsed state of "Model" PropertyGrid's items, and my handlers of the Display.ShapesSelected event get called an extra time (doing a needless work).

Is there a way to prevent this behavior (so that only the topmost shape remains selected)?

Jan 17, 2013 at 8:21 AM

Please help! :)

Jan 17, 2013 at 9:04 AM

I'm working on a solution, please be patient.

Jan 17, 2013 at 9:13 AM
Edited Jan 17, 2013 at 3:04 PM

Oh, I simply thought you didn't notice this topic.

No problem, I'll wait.

[UPDATE] Just wanna clarify that under "behavior" in the "Is there a way to prevent this behavior..." question I mean selection of shapes one after another, e.g. A-> B -> C -> A -> and so on. And not just the double-click issue. If the "selection of shapes one after another" can be prevented (e.g. by setting some property of the Diagram object) - then the double-click issue automatically goes away.