Rectangle
Contents
[
Hide
]
Create Simple Rectangle
Like previous topics, this one is also about adding a shape and this time the shape we will discuss about is Rectangle. In this topic, we have described that how developers can add simple or formatted rectangles to their slides using Aspose.Slides for C++ . To add a simple rectangle to a selected slide of the presentation, please follow the steps below:
- Create an instance of Presentation class.
- Obtain the reference of a slide by using its Index.
- Add an IAutoShape of Rectangle type using AddAutoShape method exposed by IShapes object.
- Write the modified presentation as a PPTX file.
In the example given below, we have added a simple rectangle to the first slide of the presentation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// The path to the documents directory. | |
const String outPath = u"../out/SimpleRectangle.pptx"; | |
const String templatePath = u"../templates/HelloWorld.pptx"; | |
// Load the desired the presentation | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(); | |
// Access first slide | |
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0); | |
// Add autoshape of ellipse type | |
SharedPtr<IAutoShape> ashp = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 150, 150, 50); | |
// Save PPTX to Disk | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
Create Formatted Rectangle
To add a formatted rectangle to a slide, please follow the steps below:
- Create an instance of Presentation class.
- Obtain the reference of a slide by using its Index.
- Add an IAutoShape of Rectangle type using AddAutoShape method exposed by IShapes object.
- Set the Fill Type of the Rectangle to Solid.
- Set the Color of the Rectangle using SolidFillColor.Color property as exposed by FillFormat object associated with the IShape object.
- Set the Color of the lines of the Rectangle.
- Set the Width of the lines of the Rectangle.
- Write the modified presentation as PPTX file. The above steps are implemented in the example given below.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// The path to the documents directory. | |
const String outPath = u"../out/FormattedRectangle_out.pptx"; | |
const String templatePath = u"../templates/AltText.pptx"; | |
// Load the desired the presentation | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(); | |
// Access first slide | |
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0); | |
// Add an autoshape of type line | |
SharedPtr<IAutoShape> shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 50, 150, 150, 75); | |
// Set the fill color of the rectangle shape | |
shape->get_FillFormat()->set_FillType(FillType::Solid); | |
shape->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_White()); | |
// Apply some formatting on the line | |
shape->get_LineFormat()->set_Style(LineStyle::ThickThin); | |
shape->get_LineFormat()->set_Width(7); | |
shape->get_LineFormat()->set_DashStyle(LineDashStyle::Dash); | |
shape->get_LineFormat()->get_FillFormat()->set_FillType(FillType::Solid); | |
shape->get_LineFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Blue()); | |
//Write the PPTX to Disk | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |