Search code examples
c#.netpowerpointaspose

Aspose Slide for .net C# change text color of a shape


I can't find a way to change text color of a rectangle autoshape, please could I have help?

here code extract:

// Add shape


IAutoShape shape= slide.Shapes.AddAutoShape(ShapeType.Rectangle, 20, 677, 250, 40);


                                               

((IAutoShape)shape).AddTextFrame( "Hello world!");

Default color is white, how can I change it?


Solution

  • I've done this way and It works:

    //In order to Have a no filled rectangle
    ((IAutoShape)shape).FillFormat.FillType = FillType.NoFill;
    
    
    ITextFrame tf1 = ((IAutoShape)shape).TextFrame;
    
    
            // Accessing the first Paragraph of validityDate
            IParagraph para1 = tf1.Paragraphs[0];
    
            // Accessing the first portion
            IPortion port1 = para1.Portions[0];
    
            // Define new fonts
            FontData fd1 = new FontData("Arial");
    
            // Assign new fonts to portion
            port1.PortionFormat.LatinFont = fd1;
    
            // Set font color
            port1.PortionFormat.FillFormat.FillType = FillType.Solid;
            port1.PortionFormat.FillFormat.SolidFillColor.Color = Color.Gray;
    
            // Set the Height of the Font
            port1.PortionFormat.FontHeight = 13;