Displaying shapes

we are able to display shapes individually… but there is a problem in displaying it when contained in a group shape. we are not able to get exact co-ordinates of shape, for eg rectangle when it is present in group shape. how to get top,left,height and width of the shape which is in group shape or containing block.

Please hold on for a while. I will try to compose an example and post it here in about an hour or so.

Here is the code that gets the binding rectangle of the shape:

private RectangleF GetShapeRec(ShapeBase shape)

{

if (shape.IsTopLevel)

{

return new RectangleF(

(float)shape.Left,

(float)shape.Top,

(float)shape.Width,

(float)shape.Height);

}

else

{

GroupShape group = (GroupShape)shape.ParentNode;

double shapeLeft = group.Left + (shape.Left - group.CoordOrigin.X) * group.Width / group.CoordSize.Width;

double shapeTop = group.Top + (shape.Top - group.CoordOrigin.Y) * group.Height / group.CoordSize.Height;

double shapeWidth = shape.Width * group.Width / group.CoordSize.Width;

double shapeHeight = shape.Height * group.Height / group.CoordSize.Height;

return new RectangleF(

(float)shapeLeft,

(float)shapeTop,

(float)shapeWidth,

(float)shapeHeight);

}

}

Please note that the acquired coordinates are absolute only if the shape is floating. If the shape is inline, its coordinates are relative to a shape position in text (char and line), and that is hard to convert into absolute coordinates.

Also note that the resulting coordinates are relative to page text boundaries, that is to the area of the page that is limited by page margins and gutter.

Hope this helps. Please let me know if you have further questions.

thanks a lot… this is exactly what we required.

There is also ShapeBase.LocalToParent method which converts coordinates of this shape's coordinate system to the coordinate system of the parent shape. If you are deep several levels inside group shapes, you would need to loop through the parent shapes while invoking this method.

Basically, top level shapes are positioned and sized in points.

Child shapes are positioned and sized in the coordinate space of the parent shape that is specified using CoordOrigin and CoordSize properties of the parent shape. This is VML basically, exactly as MS Office uses it in WordML files.