Free Support Forum - aspose.com

Positioning a rectangle

Hi,

I have added a rectangle to my slide using the sample code from the documentation.

Like this:

//Add autoshape of rectangle type


int idx = sld.Shapes.AddAutoShape(ShapeTypeEx.Rectangle, 50, 150, 150, 50);


ShapeEx shp = sld.Shapes[idx];


This does add the rectangle but it always seems to add it in the same place on the slide. I would expect that he four integers that are part of the code (in this case 50, 150, 150, 50) would position the rectangle on the slide but when I change them it does not seem to make a difference to the final position of the rectangle.

What am I missing? What do I need to do to position the rectangle?

Please help.

Thanks,

PatC





Hi Pat,

I have observed the code snippet and there is no issue with it. The four properties seems to work fine on my end using Aspose.Slides for .NET 5.2.0. For your kind reference, I have shared a code snippet with you in which I have created two rectangles and have assigned different values to the mentioned integers for X, Y, Width and Height position. It seems to work for me. If you still encounter any issue then please share the generated presentation along with your project code for necessary investigation on our end.

//Instantiate PrseetationEx class that represents the PPTX

PresentationEx pres = new PresentationEx();

SlideEx sld = pres.Slides[0];

//Add autoshape of rectangle type

sld.Shapes.AddAutoShape(ShapeTypeEx.Rectangle, 50, 150, 350, 350);

sld.Shapes.AddAutoShape(ShapeTypeEx.Rectangle, 420, 20, 150, 250);

//Write the PPTX file to disk

pres.Write("d:\\RectShp1.pptx");

Thanks and Regards,