shapegroup selection

Sep 19, 2012 at 7:18 PM

When I group shapes together to form a shapegroup, the selectIon of any object selects the entIre group fIrst.   I dont want the group to be selected on the fIrst mouseclIck.  When I clIck a shape In a shapegroup, I want the shape to be selected fIrst. How do I do thIs?

 Also, when In "guess" mode, I dont want the user to be able to select the groupshape at all. When I am In guess mode, I just want users to be able to select the shape, not the shapegroup that It belongs to. How do I do this???



Sep 20, 2012 at 7:35 AM
Edited Sep 20, 2012 at 7:44 AM

Add an event handler to the display's ShapesSelected event and use this code snippet:

if (display.SelectedShapes.Count == 1						
	// The selected shape has to be a shape group
	&& display.SelectedShapes.TopMost is IShapeGroup	
	// The shape group must not be empty
	&& display.SelectedShapes.TopMost.Children.Count > 0)	
	// Transform mouse (screen) coordinates into diagram coordinates
	Point mousePos = Point.Empty;
	display.ScreenToDiagram(Control.MousePosition, out mousePos);
	// Search the clicked shape inside the group's Children shape collection.
	// Specify control point capabilities 'None' in order to search for whole shapes
	// The last parameter specifies the shape where to start (used for cycling 
	// through overlapping shapes)
	Shape childShape = display.SelectedShapes.TopMost.Children.FindShape(
							mousePos.X, mousePos.Y, 
							ControlPointCapabilities.None, 0, null);
	if (childShape != null) display.SelectShape(childShape, false);

Sep 20, 2012 at 10:52 AM

this works great! thanks much. :)

I still have 1 minor problem...  the other shapes in the shapegroup have a "light grey" selection rectangle around them, when i select any shape in the shapegroup.

The current selection is perfect, but then it puts "grey rectangle" around the other shapes in the shapegroup.  

How do i get rid of the grey rectangle around the other shapes in the shapegroup???


Sep 20, 2012 at 2:55 PM

display.SelectionInactiveColor = Color.Transparent;
This also affects disabled connection points (they will be drawn without border), but there's no other way (beside overriding the IDiagramPresenter.DrawShapeOutline implementation of the Display).