With Spire.Presentation for .NET, developers can add different shapes to slides in C#. We can also use Spire.Presentation to formatting the lines of shape, such as the style, width, dash style and color of the line, etc. This article will show you how to set the format for the shape lines in C#. We will use rectangle for example. Here comes to the code snippet:
Step 1: Create a PPT document.
Presentation presentation = new Presentation();
Step 2: Add a rectangle shape to the slide.
IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 100, 100, 100));
Step 3: Set the fill color of the rectangle shape.
shape.Fill.FillType = FillFormatType.Solid; shape.Fill.SolidColor.Color = Color.White;
Step 4: Apply some formatting on the line of the rectangle.
shape.Line.Style = TextLineStyle.ThickThin; shape.Line.Width = 5; shape.Line.DashStyle = LineDashStyleType.Dash;
Step 5: Set the color of the line of the rectangle.
shape.ShapeStyle.LineColor.Color = Color.Red;
Step 6: Save the document to file.
presentation.SaveToFile("shape.pptx", FileFormat.Pptx2010);
Effective screenshot:
Full codes:
using Spire.Presentation; using Spire.Presentation.Drawing; using System.Drawing; namespace SetFormat { class Program { static void Main(string[] args) { Presentation presentation = new Presentation(); IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 100, 100, 100)); shape.Fill.FillType = FillFormatType.Solid; shape.Fill.SolidColor.Color = Color.White; shape.Line.Style = TextLineStyle.ThickThin; shape.Line.Width = 5; shape.Line.DashStyle = LineDashStyleType.Dash; shape.ShapeStyle.LineColor.Color = Color.Red; presentation.SaveToFile("shape.pptx", FileFormat.Pptx2010); } } }