Aspose::Words::BorderCollection Class Referencefinal

Detailed Description

A collection of Border objects.

Examples

Shows how to insert a paragraph with a top border.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<Border> topBorder = builder->get_ParagraphFormat()->get_Borders()->idx_get(BorderType::Top);
topBorder->set_Color(System::Drawing::Color::get_Red());
topBorder->set_LineWidth(4.0);
topBorder->set_LineStyle(LineStyle::DashSmallGap);
builder->Writeln(u"Text with a red top border.");
doc->Save(ArtifactsDir + u"Border.ParagraphTopBorder.docx");

#include <Aspose.Words.Cpp/BorderCollection.h>

+ Inheritance diagram for Aspose::Words::BorderCollection:

Public Member Functions

void ClearFormatting ()
 Removes all borders of an object. More...
 
bool Equals (const SharedPtr< BorderCollection > &brColl)
 Compares collections of borders. More...
 
SharedPtr< Borderget_Bottom ()
 Gets the bottom border. More...
 
Color get_Color ()
 Gets or sets the border color. More...
 
int32_t get_Count ()
 Gets the number of borders in the collection. More...
 
double get_DistanceFromText ()
 Gets or sets distance of the border from text in points. More...
 
SharedPtr< Borderget_Horizontal ()
 Gets the horizontal border that is used between cells or conforming paragraphs. More...
 
SharedPtr< Borderget_Left ()
 Gets the left border. More...
 
LineStyle get_LineStyle ()
 Gets or sets the border style. More...
 
double get_LineWidth ()
 Gets or sets the border width in points. More...
 
SharedPtr< Borderget_Right ()
 Gets the right border. More...
 
bool get_Shadow ()
 Gets or sets a value indicating whether the border has a shadow. More...
 
SharedPtr< Borderget_Top ()
 Gets the top border. More...
 
SharedPtr< Borderget_Vertical ()
 Gets the vertical border that is used between cells. More...
 
SharedPtr< IEnumerator< SharedPtr< Border > > > GetEnumerator () override
 Returns an enumerator object that can be used to iterate over all borders in the collection. More...
 
virtual const TypeInfoGetType () const override
 
SharedPtr< Borderidx_get (BorderType borderType)
 Retrieves a Border object by border type. More...
 
SharedPtr< Borderidx_get (int32_t index)
 Retrieves a Border object by index. More...
 
virtual bool Is (const TypeInfo &target) const override
 
void set_Color (Color value)
 Setter for get_Color. More...
 
void set_DistanceFromText (double value)
 Setter for get_DistanceFromText. More...
 
void set_LineStyle (LineStyle value)
 Setter for get_LineStyle. More...
 
void set_LineWidth (double value)
 Setter for get_LineWidth. More...
 
void set_Shadow (bool value)
 Setter for get_Shadow. More...
 

Static Public Member Functions

static const TypeInfoType ()
 

Member Function Documentation

◆ ClearFormatting()

void Aspose::Words::BorderCollection::ClearFormatting ( )

Removes all borders of an object.

Examples

Shows how to remove all borders from all paragraphs in a document.

auto doc = MakeObject<Document>(MyDir + u"Borders.docx");
// The first paragraph of this document has visible borders with these settings.
SharedPtr<BorderCollection> firstParagraphBorders = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat()->get_Borders();
ASSERT_EQ(System::Drawing::Color::get_Red().ToArgb(), firstParagraphBorders->get_Color().ToArgb());
ASSERT_EQ(LineStyle::Single, firstParagraphBorders->get_LineStyle());
ASPOSE_ASSERT_EQ(3.0, firstParagraphBorders->get_LineWidth());
// Use the "ClearFormatting" method on each paragraph to remove all borders.
for (const auto& paragraph : System::IterateOver<Paragraph>(doc->get_FirstSection()->get_Body()->get_Paragraphs()))
{
paragraph->get_ParagraphFormat()->get_Borders()->ClearFormatting();
for (const auto& border : System::IterateOver(paragraph->get_ParagraphFormat()->get_Borders()))
{
ASSERT_EQ(System::Drawing::Color::Empty.ToArgb(), border->get_Color().ToArgb());
ASSERT_EQ(LineStyle::None, border->get_LineStyle());
ASPOSE_ASSERT_EQ(0.0, border->get_LineWidth());
}
}
doc->Save(ArtifactsDir + u"BorderCollection.RemoveAllBorders.docx");

◆ Equals()

bool Aspose::Words::BorderCollection::Equals ( const System::SharedPtr< Aspose::Words::BorderCollection > &  brColl)

Compares collections of borders.

Examples

Shows how border collections can share elements.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Paragraph 1.");
builder->Write(u"Paragraph 2.");
// Since we used the same border configuration while creating
// these paragraphs, their border collections share the same elements.
SharedPtr<BorderCollection> firstParagraphBorders = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat()->get_Borders();
SharedPtr<BorderCollection> secondParagraphBorders = builder->get_CurrentParagraph()->get_ParagraphFormat()->get_Borders();
for (int i = 0; i < firstParagraphBorders->get_Count(); i++)
{
ASSERT_TRUE(System::ObjectExt::Equals(firstParagraphBorders->idx_get(i), secondParagraphBorders->idx_get(i)));
ASSERT_EQ(System::ObjectExt::GetHashCode(firstParagraphBorders->idx_get(i)), System::ObjectExt::GetHashCode(secondParagraphBorders->idx_get(i)));
ASSERT_FALSE(firstParagraphBorders->idx_get(i)->get_IsVisible());
}
for (const auto& border : System::IterateOver(secondParagraphBorders))
{
border->set_LineStyle(LineStyle::DotDash);
}
// After changing the line style of the borders in just the second paragraph,
// the border collections no longer share the same elements.
for (int i = 0; i < firstParagraphBorders->get_Count(); i++)
{
ASSERT_FALSE(System::ObjectExt::Equals(firstParagraphBorders->idx_get(i), secondParagraphBorders->idx_get(i)));
ASSERT_NE(System::ObjectExt::GetHashCode(firstParagraphBorders->idx_get(i)), System::ObjectExt::GetHashCode(secondParagraphBorders->idx_get(i)));
// Changing the appearance of an empty border makes it visible.
ASSERT_TRUE(secondParagraphBorders->idx_get(i)->get_IsVisible());
}
doc->Save(ArtifactsDir + u"Border.SharedElements.docx");

◆ get_Bottom()

System::SharedPtr<Aspose::Words::Border> Aspose::Words::BorderCollection::get_Bottom ( )

Gets the bottom border.

Examples

Shows how to apply border and shading color while building a table.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Start a table and set a default color/thickness for its borders.
SharedPtr<Table> table = builder->StartTable();
// Create a row with two cells with different background colors.
builder->InsertCell();
builder->get_CellFormat()->get_Shading()->set_BackgroundPatternColor(System::Drawing::Color::get_LightSkyBlue());
builder->Writeln(u"Row 1, Cell 1.");
builder->InsertCell();
builder->get_CellFormat()->get_Shading()->set_BackgroundPatternColor(System::Drawing::Color::get_Orange());
builder->Writeln(u"Row 1, Cell 2.");
builder->EndRow();
// Reset cell formatting to disable the background colors
// set a custom border thickness for all new cells created by the builder,
// then build a second row.
builder->get_CellFormat()->ClearFormatting();
builder->get_CellFormat()->get_Borders()->get_Left()->set_LineWidth(4.0);
builder->get_CellFormat()->get_Borders()->get_Right()->set_LineWidth(4.0);
builder->get_CellFormat()->get_Borders()->get_Top()->set_LineWidth(4.0);
builder->get_CellFormat()->get_Borders()->get_Bottom()->set_LineWidth(4.0);
builder->InsertCell();
builder->Writeln(u"Row 2, Cell 1.");
builder->InsertCell();
builder->Writeln(u"Row 2, Cell 2.");
doc->Save(ArtifactsDir + u"DocumentBuilder.TableBordersAndShading.docx");

◆ get_Color()

System::Drawing::Color Aspose::Words::BorderCollection::get_Color ( )

Gets or sets the border color.

Returns the color of the first border in the collection.

Sets the color of all borders in the collection excluding diagonal borders.

Examples

Shows how to create green wavy page border with a shadow.

auto doc = MakeObject<Document>();
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
pageSetup->get_Borders()->set_LineStyle(LineStyle::DoubleWave);
pageSetup->get_Borders()->set_LineWidth(2);
pageSetup->get_Borders()->set_Color(System::Drawing::Color::get_Green());
pageSetup->get_Borders()->set_DistanceFromText(24);
pageSetup->get_Borders()->set_Shadow(true);
doc->Save(ArtifactsDir + u"PageSetup.PageBorders.docx");

◆ get_Count()

int32_t Aspose::Words::BorderCollection::get_Count ( )

Gets the number of borders in the collection.

Examples

Shows how border collections can share elements.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Paragraph 1.");
builder->Write(u"Paragraph 2.");
// Since we used the same border configuration while creating
// these paragraphs, their border collections share the same elements.
SharedPtr<BorderCollection> firstParagraphBorders = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat()->get_Borders();
SharedPtr<BorderCollection> secondParagraphBorders = builder->get_CurrentParagraph()->get_ParagraphFormat()->get_Borders();
for (int i = 0; i < firstParagraphBorders->get_Count(); i++)
{
ASSERT_TRUE(System::ObjectExt::Equals(firstParagraphBorders->idx_get(i), secondParagraphBorders->idx_get(i)));
ASSERT_EQ(System::ObjectExt::GetHashCode(firstParagraphBorders->idx_get(i)), System::ObjectExt::GetHashCode(secondParagraphBorders->idx_get(i)));
ASSERT_FALSE(firstParagraphBorders->idx_get(i)->get_IsVisible());
}
for (const auto& border : System::IterateOver(secondParagraphBorders))
{
border->set_LineStyle(LineStyle::DotDash);
}
// After changing the line style of the borders in just the second paragraph,
// the border collections no longer share the same elements.
for (int i = 0; i < firstParagraphBorders->get_Count(); i++)
{
ASSERT_FALSE(System::ObjectExt::Equals(firstParagraphBorders->idx_get(i), secondParagraphBorders->idx_get(i)));
ASSERT_NE(System::ObjectExt::GetHashCode(firstParagraphBorders->idx_get(i)), System::ObjectExt::GetHashCode(secondParagraphBorders->idx_get(i)));
// Changing the appearance of an empty border makes it visible.
ASSERT_TRUE(secondParagraphBorders->idx_get(i)->get_IsVisible());
}
doc->Save(ArtifactsDir + u"Border.SharedElements.docx");

◆ get_DistanceFromText()

double Aspose::Words::BorderCollection::get_DistanceFromText ( )

Gets or sets distance of the border from text in points.

Gets the distance from text for the first border.

Sets the distance from text for all borders in the collection excluding diagonal borders.

Has no effect and will be automatically reset to zero for borders of table cells.

Examples

Shows how to create green wavy page border with a shadow.

auto doc = MakeObject<Document>();
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
pageSetup->get_Borders()->set_LineStyle(LineStyle::DoubleWave);
pageSetup->get_Borders()->set_LineWidth(2);
pageSetup->get_Borders()->set_Color(System::Drawing::Color::get_Green());
pageSetup->get_Borders()->set_DistanceFromText(24);
pageSetup->get_Borders()->set_Shadow(true);
doc->Save(ArtifactsDir + u"PageSetup.PageBorders.docx");

◆ get_Horizontal()

System::SharedPtr<Aspose::Words::Border> Aspose::Words::BorderCollection::get_Horizontal ( )

Gets the horizontal border that is used between cells or conforming paragraphs.

Examples

Shows how to apply settings to horizontal borders to a paragraph's format.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Create a red horizontal border for the paragraph. Any paragraphs created afterwards will inherit these border settings.
SharedPtr<BorderCollection> borders = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat()->get_Borders();
borders->get_Horizontal()->set_Color(System::Drawing::Color::get_Red());
borders->get_Horizontal()->set_LineStyle(LineStyle::DashSmallGap);
borders->get_Horizontal()->set_LineWidth(3);
// Write text to the document without creating a new paragraph afterward.
// Since there is no paragraph underneath, the horizontal border will not be visible.
builder->Write(u"Paragraph above horizontal border.");
// Once we add a second paragraph, the border of the first paragraph will become visible.
builder->InsertParagraph();
builder->Write(u"Paragraph below horizontal border.");
doc->Save(ArtifactsDir + u"Border.HorizontalBorders.docx");

Shows how to apply settings to vertical borders to a table row's format.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Create a table with red and blue inner borders.
SharedPtr<Table> table = builder->StartTable();
for (int i = 0; i < 3; i++)
{
builder->InsertCell();
builder->Write(String::Format(u"Row {0}, Column 1", i + 1));
builder->InsertCell();
builder->Write(String::Format(u"Row {0}, Column 2", i + 1));
SharedPtr<Row> row = builder->EndRow();
SharedPtr<BorderCollection> borders = row->get_RowFormat()->get_Borders();
// Adjust the appearance of borders that will appear between rows.
borders->get_Horizontal()->set_Color(System::Drawing::Color::get_Red());
borders->get_Horizontal()->set_LineStyle(LineStyle::Dot);
borders->get_Horizontal()->set_LineWidth(2.0);
// Adjust the appearance of borders that will appear between cells.
borders->get_Vertical()->set_Color(System::Drawing::Color::get_Blue());
borders->get_Vertical()->set_LineStyle(LineStyle::Dot);
borders->get_Vertical()->set_LineWidth(2.0);
}
// A row format, and a cell's inner paragraph use different border settings.
SharedPtr<Border> border = table->get_FirstRow()->get_FirstCell()->get_LastParagraph()->get_ParagraphFormat()->get_Borders()->get_Vertical();
ASSERT_EQ(System::Drawing::Color::Empty.ToArgb(), border->get_Color().ToArgb());
ASPOSE_ASSERT_EQ(0.0, border->get_LineWidth());
ASSERT_EQ(LineStyle::None, border->get_LineStyle());
doc->Save(ArtifactsDir + u"Border.VerticalBorders.docx");

◆ get_Left()

System::SharedPtr<Aspose::Words::Border> Aspose::Words::BorderCollection::get_Left ( )

Gets the left border.

Examples

Shows how to apply border and shading color while building a table.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Start a table and set a default color/thickness for its borders.
SharedPtr<Table> table = builder->StartTable();
// Create a row with two cells with different background colors.
builder->InsertCell();
builder->get_CellFormat()->get_Shading()->set_BackgroundPatternColor(System::Drawing::Color::get_LightSkyBlue());
builder->Writeln(u"Row 1, Cell 1.");
builder->InsertCell();
builder->get_CellFormat()->get_Shading()->set_BackgroundPatternColor(System::Drawing::Color::get_Orange());
builder->Writeln(u"Row 1, Cell 2.");
builder->EndRow();
// Reset cell formatting to disable the background colors
// set a custom border thickness for all new cells created by the builder,
// then build a second row.
builder->get_CellFormat()->ClearFormatting();
builder->get_CellFormat()->get_Borders()->get_Left()->set_LineWidth(4.0);
builder->get_CellFormat()->get_Borders()->get_Right()->set_LineWidth(4.0);
builder->get_CellFormat()->get_Borders()->get_Top()->set_LineWidth(4.0);
builder->get_CellFormat()->get_Borders()->get_Bottom()->set_LineWidth(4.0);
builder->InsertCell();
builder->Writeln(u"Row 2, Cell 1.");
builder->InsertCell();
builder->Writeln(u"Row 2, Cell 2.");
doc->Save(ArtifactsDir + u"DocumentBuilder.TableBordersAndShading.docx");

◆ get_LineStyle()

Aspose::Words::LineStyle Aspose::Words::BorderCollection::get_LineStyle ( )

Gets or sets the border style.

Returns the style of the first border in the collection.

Sets the style of all borders in the collection excluding diagonal borders.

Examples

Shows how to create green wavy page border with a shadow.

auto doc = MakeObject<Document>();
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
pageSetup->get_Borders()->set_LineStyle(LineStyle::DoubleWave);
pageSetup->get_Borders()->set_LineWidth(2);
pageSetup->get_Borders()->set_Color(System::Drawing::Color::get_Green());
pageSetup->get_Borders()->set_DistanceFromText(24);
pageSetup->get_Borders()->set_Shadow(true);
doc->Save(ArtifactsDir + u"PageSetup.PageBorders.docx");

◆ get_LineWidth()

double Aspose::Words::BorderCollection::get_LineWidth ( )

Gets or sets the border width in points.

Returns the width of the first border in the collection.

Sets the width of all borders in the collection excluding diagonal borders.

Examples

Shows how to create green wavy page border with a shadow.

auto doc = MakeObject<Document>();
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
pageSetup->get_Borders()->set_LineStyle(LineStyle::DoubleWave);
pageSetup->get_Borders()->set_LineWidth(2);
pageSetup->get_Borders()->set_Color(System::Drawing::Color::get_Green());
pageSetup->get_Borders()->set_DistanceFromText(24);
pageSetup->get_Borders()->set_Shadow(true);
doc->Save(ArtifactsDir + u"PageSetup.PageBorders.docx");

◆ get_Right()

System::SharedPtr<Aspose::Words::Border> Aspose::Words::BorderCollection::get_Right ( )

Gets the right border.

Examples

Shows how to apply border and shading color while building a table.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Start a table and set a default color/thickness for its borders.
SharedPtr<Table> table = builder->StartTable();
// Create a row with two cells with different background colors.
builder->InsertCell();
builder->get_CellFormat()->get_Shading()->set_BackgroundPatternColor(System::Drawing::Color::get_LightSkyBlue());
builder->Writeln(u"Row 1, Cell 1.");
builder->InsertCell();
builder->get_CellFormat()->get_Shading()->set_BackgroundPatternColor(System::Drawing::Color::get_Orange());
builder->Writeln(u"Row 1, Cell 2.");
builder->EndRow();
// Reset cell formatting to disable the background colors
// set a custom border thickness for all new cells created by the builder,
// then build a second row.
builder->get_CellFormat()->ClearFormatting();
builder->get_CellFormat()->get_Borders()->get_Left()->set_LineWidth(4.0);
builder->get_CellFormat()->get_Borders()->get_Right()->set_LineWidth(4.0);
builder->get_CellFormat()->get_Borders()->get_Top()->set_LineWidth(4.0);
builder->get_CellFormat()->get_Borders()->get_Bottom()->set_LineWidth(4.0);
builder->InsertCell();
builder->Writeln(u"Row 2, Cell 1.");
builder->InsertCell();
builder->Writeln(u"Row 2, Cell 2.");
doc->Save(ArtifactsDir + u"DocumentBuilder.TableBordersAndShading.docx");

◆ get_Shadow()

bool Aspose::Words::BorderCollection::get_Shadow ( )

Gets or sets a value indicating whether the border has a shadow.

Gets the value from the first border in the collection.

Sets the value for all borders in the collection excluding diagonal borders.

Examples

Shows how to create green wavy page border with a shadow.

auto doc = MakeObject<Document>();
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
pageSetup->get_Borders()->set_LineStyle(LineStyle::DoubleWave);
pageSetup->get_Borders()->set_LineWidth(2);
pageSetup->get_Borders()->set_Color(System::Drawing::Color::get_Green());
pageSetup->get_Borders()->set_DistanceFromText(24);
pageSetup->get_Borders()->set_Shadow(true);
doc->Save(ArtifactsDir + u"PageSetup.PageBorders.docx");

◆ get_Top()

System::SharedPtr<Aspose::Words::Border> Aspose::Words::BorderCollection::get_Top ( )

Gets the top border.

Examples

Shows how to apply border and shading color while building a table.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Start a table and set a default color/thickness for its borders.
SharedPtr<Table> table = builder->StartTable();
// Create a row with two cells with different background colors.
builder->InsertCell();
builder->get_CellFormat()->get_Shading()->set_BackgroundPatternColor(System::Drawing::Color::get_LightSkyBlue());
builder->Writeln(u"Row 1, Cell 1.");
builder->InsertCell();
builder->get_CellFormat()->get_Shading()->set_BackgroundPatternColor(System::Drawing::Color::get_Orange());
builder->Writeln(u"Row 1, Cell 2.");
builder->EndRow();
// Reset cell formatting to disable the background colors
// set a custom border thickness for all new cells created by the builder,
// then build a second row.
builder->get_CellFormat()->ClearFormatting();
builder->get_CellFormat()->get_Borders()->get_Left()->set_LineWidth(4.0);
builder->get_CellFormat()->get_Borders()->get_Right()->set_LineWidth(4.0);
builder->get_CellFormat()->get_Borders()->get_Top()->set_LineWidth(4.0);
builder->get_CellFormat()->get_Borders()->get_Bottom()->set_LineWidth(4.0);
builder->InsertCell();
builder->Writeln(u"Row 2, Cell 1.");
builder->InsertCell();
builder->Writeln(u"Row 2, Cell 2.");
doc->Save(ArtifactsDir + u"DocumentBuilder.TableBordersAndShading.docx");

◆ get_Vertical()

System::SharedPtr<Aspose::Words::Border> Aspose::Words::BorderCollection::get_Vertical ( )

Gets the vertical border that is used between cells.

Examples

Shows how to apply settings to vertical borders to a table row's format.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Create a table with red and blue inner borders.
SharedPtr<Table> table = builder->StartTable();
for (int i = 0; i < 3; i++)
{
builder->InsertCell();
builder->Write(String::Format(u"Row {0}, Column 1", i + 1));
builder->InsertCell();
builder->Write(String::Format(u"Row {0}, Column 2", i + 1));
SharedPtr<Row> row = builder->EndRow();
SharedPtr<BorderCollection> borders = row->get_RowFormat()->get_Borders();
// Adjust the appearance of borders that will appear between rows.
borders->get_Horizontal()->set_Color(System::Drawing::Color::get_Red());
borders->get_Horizontal()->set_LineStyle(LineStyle::Dot);
borders->get_Horizontal()->set_LineWidth(2.0);
// Adjust the appearance of borders that will appear between cells.
borders->get_Vertical()->set_Color(System::Drawing::Color::get_Blue());
borders->get_Vertical()->set_LineStyle(LineStyle::Dot);
borders->get_Vertical()->set_LineWidth(2.0);
}
// A row format, and a cell's inner paragraph use different border settings.
SharedPtr<Border> border = table->get_FirstRow()->get_FirstCell()->get_LastParagraph()->get_ParagraphFormat()->get_Borders()->get_Vertical();
ASSERT_EQ(System::Drawing::Color::Empty.ToArgb(), border->get_Color().ToArgb());
ASPOSE_ASSERT_EQ(0.0, border->get_LineWidth());
ASSERT_EQ(LineStyle::None, border->get_LineStyle());
doc->Save(ArtifactsDir + u"Border.VerticalBorders.docx");

◆ GetEnumerator()

System::SharedPtr<System::Collections::Generic::IEnumerator<System::SharedPtr<Aspose::Words::Border> > > Aspose::Words::BorderCollection::GetEnumerator ( )
override

Returns an enumerator object that can be used to iterate over all borders in the collection.

Examples

Shows how to iterate over and edit all of the borders in a paragraph format object.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Configure the builder's paragraph format settings to create a green wave border on all sides.
SharedPtr<BorderCollection> borders = builder->get_ParagraphFormat()->get_Borders();
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<Border>>> enumerator = borders->GetEnumerator();
while (enumerator->MoveNext())
{
SharedPtr<Border> border = enumerator->get_Current();
border->set_Color(System::Drawing::Color::get_Green());
border->set_LineStyle(LineStyle::Wave);
border->set_LineWidth(3);
}
}
// Insert a paragraph. Our border settings will determine the appearance of its border.
builder->Writeln(u"Hello world!");
doc->Save(ArtifactsDir + u"BorderCollection.GetBordersEnumerator.docx");

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::BorderCollection::GetType ( ) const
overridevirtual

Reimplemented from System::Object.

◆ idx_get() [1/2]

System::SharedPtr<Aspose::Words::Border> Aspose::Words::BorderCollection::idx_get ( Aspose::Words::BorderType  borderType)

Retrieves a Border object by border type.

Note that not all borders are present for different document elements. This method throws an exception if you request a border not applicable to the current object.

Parameters
borderTypeA BorderType value that specifies the type of the border to retrieve.
Examples

Shows how to decorate text with borders and shading.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
SharedPtr<BorderCollection> borders = builder->get_ParagraphFormat()->get_Borders();
borders->set_DistanceFromText(20);
borders->idx_get(BorderType::Left)->set_LineStyle(LineStyle::Double);
borders->idx_get(BorderType::Right)->set_LineStyle(LineStyle::Double);
borders->idx_get(BorderType::Top)->set_LineStyle(LineStyle::Double);
borders->idx_get(BorderType::Bottom)->set_LineStyle(LineStyle::Double);
SharedPtr<Shading> shading = builder->get_ParagraphFormat()->get_Shading();
shading->set_Texture(TextureIndex::TextureDiagonalCross);
shading->set_BackgroundPatternColor(System::Drawing::Color::get_LightCoral());
shading->set_ForegroundPatternColor(System::Drawing::Color::get_LightSalmon());
builder->Write(u"This paragraph is formatted with a double border and shading.");
doc->Save(ArtifactsDir + u"DocumentBuilder.ApplyBordersAndShading.docx");

◆ idx_get() [2/2]

System::SharedPtr<Aspose::Words::Border> Aspose::Words::BorderCollection::idx_get ( int32_t  index)

Retrieves a Border object by index.

Parameters
indexZero-based index of the border to retrieve.
Examples

Shows how border collections can share elements.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Paragraph 1.");
builder->Write(u"Paragraph 2.");
// Since we used the same border configuration while creating
// these paragraphs, their border collections share the same elements.
SharedPtr<BorderCollection> firstParagraphBorders = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat()->get_Borders();
SharedPtr<BorderCollection> secondParagraphBorders = builder->get_CurrentParagraph()->get_ParagraphFormat()->get_Borders();
for (int i = 0; i < firstParagraphBorders->get_Count(); i++)
{
ASSERT_TRUE(System::ObjectExt::Equals(firstParagraphBorders->idx_get(i), secondParagraphBorders->idx_get(i)));
ASSERT_EQ(System::ObjectExt::GetHashCode(firstParagraphBorders->idx_get(i)), System::ObjectExt::GetHashCode(secondParagraphBorders->idx_get(i)));
ASSERT_FALSE(firstParagraphBorders->idx_get(i)->get_IsVisible());
}
for (const auto& border : System::IterateOver(secondParagraphBorders))
{
border->set_LineStyle(LineStyle::DotDash);
}
// After changing the line style of the borders in just the second paragraph,
// the border collections no longer share the same elements.
for (int i = 0; i < firstParagraphBorders->get_Count(); i++)
{
ASSERT_FALSE(System::ObjectExt::Equals(firstParagraphBorders->idx_get(i), secondParagraphBorders->idx_get(i)));
ASSERT_NE(System::ObjectExt::GetHashCode(firstParagraphBorders->idx_get(i)), System::ObjectExt::GetHashCode(secondParagraphBorders->idx_get(i)));
// Changing the appearance of an empty border makes it visible.
ASSERT_TRUE(secondParagraphBorders->idx_get(i)->get_IsVisible());
}
doc->Save(ArtifactsDir + u"Border.SharedElements.docx");

◆ Is()

virtual bool Aspose::Words::BorderCollection::Is ( const System::TypeInfo target) const
overridevirtual

Reimplemented from System::Object.

◆ set_Color()

void Aspose::Words::BorderCollection::set_Color ( System::Drawing::Color  value)

◆ set_DistanceFromText()

void Aspose::Words::BorderCollection::set_DistanceFromText ( double  value)

◆ set_LineStyle()

void Aspose::Words::BorderCollection::set_LineStyle ( Aspose::Words::LineStyle  value)

◆ set_LineWidth()

void Aspose::Words::BorderCollection::set_LineWidth ( double  value)

◆ set_Shadow()

void Aspose::Words::BorderCollection::set_Shadow ( bool  value)

◆ Type()

static const System::TypeInfo& Aspose::Words::BorderCollection::Type ( )
static