Detailed Description

Represents a border of an object.

Borders can be applied to various document elements including paragraph, run of text inside a paragraph or a table cell.

Examples

Shows how to insert a string surrounded by a border into a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_Font()->get_Border()->set_Color(System::Drawing::Color::get_Green());
builder->get_Font()->get_Border()->set_LineWidth(2.5);
builder->get_Font()->get_Border()->set_LineStyle(LineStyle::DashDotStroker);
builder->Write(u"Text surrounded by green border.");
doc->Save(ArtifactsDir + u"Border.FontBorder.docx");

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/Border.h>

+ Inheritance diagram for Aspose::Words::Border:

Public Member Functions

void ClearFormatting ()
 Resets border properties to default values. More...
 
bool Equals (SharedPtr< Border > rhs)
 Determines whether the specified border is equal in value to the current border. More...
 
bool Equals (SharedPtr< Object > obj) override
 Determines whether the specified object is equal in value to the current object. More...
 
Color get_Color ()
 Gets or sets the border color. More...
 
double get_DistanceFromText ()
 Gets or sets distance of the border from text or from the page edge in points. More...
 
bool get_IsVisible ()
 Returns true if the LineStyle is not LineStyle.None. More...
 
LineStyle get_LineStyle ()
 Gets or sets the border style. More...
 
double get_LineWidth ()
 Gets or sets the border width in points. More...
 
bool get_Shadow ()
 Gets or sets a value indicating whether the border has a shadow. More...
 
int32_t GetHashCode () const override
 Serves as a hash function for this type. More...
 
virtual const TypeInfoGetType () const override
 
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 ()
 
- Static Public Member Functions inherited from InternableComplexAttr
static const TypeInfoType ()
 

Member Function Documentation

◆ ClearFormatting()

void Aspose::Words::Border::ClearFormatting ( )

Resets border properties to default values.

Examples

Shows how to remove borders from a paragraph.

auto doc = MakeObject<Document>(MyDir + u"Borders.docx");
// Each paragraph has an individual set of borders.
// We can access the settings for the appearance of these borders via the paragraph format object.
SharedPtr<BorderCollection> borders = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat()->get_Borders();
ASSERT_EQ(System::Drawing::Color::get_Red().ToArgb(), borders->idx_get(0)->get_Color().ToArgb());
ASPOSE_ASSERT_EQ(3.0, borders->idx_get(0)->get_LineWidth());
ASSERT_EQ(LineStyle::Single, borders->idx_get(0)->get_LineStyle());
ASSERT_TRUE(borders->idx_get(0)->get_IsVisible());
// We can remove a border at once by running the ClearFormatting method.
// Running this method on every border of a paragraph will remove all its borders.
for (auto border : System::IterateOver(borders))
{
border->ClearFormatting();
}
ASSERT_EQ(System::Drawing::Color::Empty.ToArgb(), borders->idx_get(0)->get_Color().ToArgb());
ASPOSE_ASSERT_EQ(0.0, borders->idx_get(0)->get_LineWidth());
ASSERT_EQ(LineStyle::None, borders->idx_get(0)->get_LineStyle());
ASSERT_FALSE(borders->idx_get(0)->get_IsVisible());
doc->Save(ArtifactsDir + u"Border.ClearFormatting.docx");

◆ Equals() [1/2]

bool Aspose::Words::Border::Equals ( System::SharedPtr< Aspose::Words::Border rhs)

Determines whether the specified border is equal in value to the current border.

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 (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");

◆ Equals() [2/2]

bool Aspose::Words::Border::Equals ( System::SharedPtr< System::Object obj)
override

Determines whether the specified object is equal in value to the current object.

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 (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_Color()

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

Gets or sets the border color.

Examples

Shows how to insert a string surrounded by a border into a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_Font()->get_Border()->set_Color(System::Drawing::Color::get_Green());
builder->get_Font()->get_Border()->set_LineWidth(2.5);
builder->get_Font()->get_Border()->set_LineStyle(LineStyle::DashDotStroker);
builder->Write(u"Text surrounded by green border.");
doc->Save(ArtifactsDir + u"Border.FontBorder.docx");

◆ get_DistanceFromText()

double Aspose::Words::Border::get_DistanceFromText ( )

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

See also
Aspose::Words::PageSetup::get_BorderDistanceFrom
Examples

Shows how to create a wide blue band border at the top of the first page.

auto doc = MakeObject<Document>();
SharedPtr<PageSetup> pageSetup = doc->get_Sections()->idx_get(0)->get_PageSetup();
pageSetup->set_BorderAlwaysInFront(false);
pageSetup->set_BorderDistanceFrom(PageBorderDistanceFrom::PageEdge);
pageSetup->set_BorderAppliesTo(PageBorderAppliesTo::FirstPage);
SharedPtr<Border> border = pageSetup->get_Borders()->idx_get(BorderType::Top);
border->set_LineStyle(LineStyle::Single);
border->set_LineWidth(30);
border->set_Color(System::Drawing::Color::get_Blue());
border->set_DistanceFromText(0);
doc->Save(ArtifactsDir + u"PageSetup.PageBorderProperties.docx");

◆ get_IsVisible()

bool Aspose::Words::Border::get_IsVisible ( )

Returns true if the LineStyle is not LineStyle.None.

Examples

Shows how to remove borders from a paragraph.

auto doc = MakeObject<Document>(MyDir + u"Borders.docx");
// Each paragraph has an individual set of borders.
// We can access the settings for the appearance of these borders via the paragraph format object.
SharedPtr<BorderCollection> borders = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_ParagraphFormat()->get_Borders();
ASSERT_EQ(System::Drawing::Color::get_Red().ToArgb(), borders->idx_get(0)->get_Color().ToArgb());
ASPOSE_ASSERT_EQ(3.0, borders->idx_get(0)->get_LineWidth());
ASSERT_EQ(LineStyle::Single, borders->idx_get(0)->get_LineStyle());
ASSERT_TRUE(borders->idx_get(0)->get_IsVisible());
// We can remove a border at once by running the ClearFormatting method.
// Running this method on every border of a paragraph will remove all its borders.
for (auto border : System::IterateOver(borders))
{
border->ClearFormatting();
}
ASSERT_EQ(System::Drawing::Color::Empty.ToArgb(), borders->idx_get(0)->get_Color().ToArgb());
ASPOSE_ASSERT_EQ(0.0, borders->idx_get(0)->get_LineWidth());
ASSERT_EQ(LineStyle::None, borders->idx_get(0)->get_LineStyle());
ASSERT_FALSE(borders->idx_get(0)->get_IsVisible());
doc->Save(ArtifactsDir + u"Border.ClearFormatting.docx");

◆ get_LineStyle()

Aspose::Words::LineStyle Aspose::Words::Border::get_LineStyle ( )

Gets or sets the border style.

If you set line style to none, then line width is automatically changed to zero.

Examples

Shows how to insert a string surrounded by a border into a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_Font()->get_Border()->set_Color(System::Drawing::Color::get_Green());
builder->get_Font()->get_Border()->set_LineWidth(2.5);
builder->get_Font()->get_Border()->set_LineStyle(LineStyle::DashDotStroker);
builder->Write(u"Text surrounded by green border.");
doc->Save(ArtifactsDir + u"Border.FontBorder.docx");

◆ get_LineWidth()

double Aspose::Words::Border::get_LineWidth ( )

Gets or sets the border width in points.

If you set line width greater than zero when line style is none, the line style is automatically changed to single line.

Examples

Shows how to insert a string surrounded by a border into a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_Font()->get_Border()->set_Color(System::Drawing::Color::get_Green());
builder->get_Font()->get_Border()->set_LineWidth(2.5);
builder->get_Font()->get_Border()->set_LineStyle(LineStyle::DashDotStroker);
builder->Write(u"Text surrounded by green border.");
doc->Save(ArtifactsDir + u"Border.FontBorder.docx");

◆ get_Shadow()

bool Aspose::Words::Border::get_Shadow ( )

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

In Microsoft Word, for a border to have a shadow, the borders on all four sides (left, top, right and bottom) should be of the same type, width, color and all should have the Shadow property set to true.

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");

◆ GetHashCode()

int32_t Aspose::Words::Border::GetHashCode ( ) const
overridevirtual

Serves as a hash function for this type.

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 (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");

Reimplemented from System::Object.

◆ GetType()

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

◆ Is()

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

◆ set_Color()

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

◆ set_DistanceFromText()

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

◆ set_LineStyle()

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

◆ set_LineWidth()

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

◆ set_Shadow()

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

◆ Type()

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