Free Support Forum - aspose.com

Adding textbox in shapes of IShapeCollection using Aspose.slides

Hi Team,

I have added some rectangle shapes in a slide using IshapeCollection. Now I want to add text boxes in them and make all the rectangles “Bring to front”.
Could you please help me ?
I am using Aspose.Slide version 18.1 and .Net version 4.5.
Below is the code snippet i am using
Presentation pres = new Presentation();

                // Get the first slide
               ISlide sld = pres.Slides[0];

IShapeCollection shapes = sld.Shapes;

                IAutoShape rect = null;

for(i=1; I< =10;i++)
{
rect=shapes.AddAutoShape(Aspose.Slides.ShapeType.Rectangle, 310, 110, 110, 70);
rect.FillFormat.SolidFillColor.Color = System.Drawing.Color.DeepSkyBlue;
rect.LineFormat.FillFormat.FillType = FillType.NoFill;

}

@rimadas,

I have observed your requirement and suggest you to please add following sample code in for loop of your sample code.

rect.AddTextFrame("test");

I suggest you to please visit this documentation link for your convenience as well.

Thanks Mudassir!!

The textBox is working. The code I used is,

rect.AddTextFrame(" ");
// Accessing the text frame
ITextFrame txtFrame = rect.TextFrame;

                        // Create the Paragraph object for text frame
                  IPAragrap  para = txtFrame.Paragraphs[0];

                        // Create Portion object for paragraph
                      IPortion  portion = para.Portions[0];

                        // Set Text
                        portion.Text = "Aspose TextBox";
                        portion.PortionFormat.FillFormat.FillType = FillType.Solid;
                        portion.PortionFormat.FillFormat.SolidFillColor.Color = System.Drawing.Color.DarkBlue;

Could you provide me a way to use “Bring to front” for the same rectangles with the text?

@rimadas,

Please try using following statement in your application to bring the shape forward.

slide.Shapes.Reorder(0, textboxshape);//0 means on top slide.Shapes.Count-1 mean on back

Thanks a lot mudassir!!

Can you tell me how to change front style of text in a textFrame??

The code I am using is below:

IAutoShape ashp = sld.Shapes.AddAutoShape(Aspose.Slides.ShapeType.Rectangle, 110, 40, 500, 50);
ashp.FillFormat.FillType = FillType.NoFill;
ashp.LineFormat.FillFormat.FillType = FillType.NoFill;
// Add TextFrame to the Rectangle
ashp.AddTextFrame(" ");

                // Accessing the text frame
                ITextFrame txtFrame = ashp.TextFrame;


                // Create the Paragraph object for text frame
                IParagraph para = txtFrame.Paragraphs[0];

                // Create Portion object for paragraph
                IPortion portion = para.Portions[0];


                // Set Text
                portion.Text = hdnOrgChartHeader.Value;

                //portion.Text.PadLeft(0);
                portion.PortionFormat.FillFormat.FillType = FillType.Solid;
                portion.PortionFormat.FillFormat.SolidFillColor.Color = System.Drawing.Color.DarkBlue;
                portion.PortionFormat.FontBold = NullableBool.True;

I want to change the size , style and padding of the text inside the text frame. Can you help me please??
I am using Aspose.Slide version 18.1 and .Net version 4.5.

@rimadas,

I suggest you to please visit this documentation link for your guidance to set the font related properties.