Grouping
The Group class's child classes allow grouping page elements and treating them as a single unit for layout.
Apply transparency to a group of objects using the TransparencyGroup class.
The Group class is parent class to the AnchorGroup, AreaGroup, ContentArea, TransformationGroup, and TransparencyGroup classes and represents a group of page elements.
public static void GroupExample()
{
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
Group mygroup = new Group();
mygroup.Add(new Rectangle(0, 0, 200, 200, 3));
mygroup.Add(new Line(0, 100, 100, 0, 3));
mygroup.Add(new Line(100, 0, 200, 100, 3));
mygroup.Add(new Line(200, 100, 100, 200, 3));
mygroup.Add(new Line(100, 200, 0, 100, 3));
page.Elements.Add(mygroup);
document.Draw(outputPath);
}
Public Shared Sub GroupExample()
Dim document As New Document()
Dim page As New Page()
document.Pages.Add(page)
Dim mygroup As New Group()
mygroup.Add(New Rectangle(0, 0, 200, 200, 3))
mygroup.Add(New Line(0, 100, 100, 0, 3))
mygroup.Add(New Line(100, 0, 200, 100, 3))
mygroup.Add(New Line(200, 100, 100, 200, 3))
mygroup.Add(New Line(100, 200, 0, 100, 3))
page.Elements.Add(mygroup)
document.Draw(outputPath)
End Sub
ContentArea
The ContentArea class groups contents within a specified area. The following example illustrates.
public static void ContentAreaExample()
{
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
ContentArea myArea = new ContentArea(10, 400, 400, 600);
myArea.Add(new Rectangle(0, 0, 200, 200, 3));
myArea.Add(new Line(0, 100, 100, 0, 3));
myArea.Add(new Line(100, 0, 200, 100, 3));
myArea.Add(new Line(200, 100, 100, 200, 3));
myArea.Add(new Line(100, 200, 0, 100, 3));
page.Elements.Add(myArea);
document.Draw(outputPath);
}
Public Shared Sub ContentAreaExample()
Dim document As New Document()
Dim page As New Page()
document.Pages.Add(page)
Dim myArea As New ContentArea(10, 400, 400, 600)
myArea.Add(New Rectangle(0, 0, 200, 200, 3))
myArea.Add(New Line(0, 100, 100, 0, 3))
myArea.Add(New Line(100, 0, 200, 100, 3))
myArea.Add(New Line(200, 100, 100, 200, 3))
myArea.Add(New Line(100, 200, 0, 100, 3))
page.Elements.Add(myArea)
document.Draw(outputPath)
End Sub
AreaGroup
The AreaGroup class groups page elements within a specified area and adds them to a page all at once.
The following example illustrates an AreaGroup class's x and y coordinates are always starts from the top-left corner and its constructor has a width and height.
public static void AreaGroupExample()
{
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
AreaGroup group1 = new AreaGroup(200, 200);
group1.Add(new Rectangle(0, 0, 200, 200, 3));
group1.Add(new Line(0, 100, 100, 0, 3));
group1.Add(new Line(100, 0, 200, 100, 3));
group1.Add(new Line(200, 100, 100, 200, 3));
group1.Add(new Line(100, 200, 0, 100, 3));
page.Elements.Add(group1);
document.Draw(outputPath);
}
Public Shared Sub AreaGroupExample()
Dim document As New Document()
Dim page As New Page()
document.Pages.Add(page)
Dim group1 As New AreaGroup(200, 200)
group1.Add(New Rectangle(0, 0, 200, 200, 3))
group1.Add(New Line(0, 100, 100, 0, 3))
group1.Add(New Line(100, 0, 200, 100, 3))
group1.Add(New Line(200, 100, 100, 200, 3))
group1.Add(New Line(100, 200, 0, 100, 3))
page.Elements.Add(group1)
document.Draw(outputPath)
End Sub
AnchorGroup
The AnchorGroup class groups page elements together and anchors them.
- The class has an
AnchorTo
property that specifies the anchor to use for the group and has two possible values:AnchorTo.Edges
andAnchorTo.Margins
. - The class has an
Align
property that specifies alignment and has three possible values:Align.Center
,Align.Left
, andAlign.Right
.
The following example illustrates adding a rectangle and a label to an AnchorGroup.
public static void AnchorGroupExample()
{
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
AnchorGroup group = new AnchorGroup(0, 0, Align.Left, VAlign.Center);
group.AnchorTo = AnchorTo.Margins;
group.Add(new Rectangle(0, 0, 200, 200, 1));
group.Add(new Label("A Label", 0, 300, 100,0));
page.Elements.Add(group);
document.Draw(outputPath);
}
Public Shared Sub AnchorGroupExample()
Dim document As New Document()
Dim page As New Page()
document.Pages.Add(page)
Dim group As New AnchorGroup(0, 0, Align.Left, VAlign.Center)
group.AnchorTo = AnchorTo.Margins
group.Add(New Rectangle(0, 0, 200, 200, 1))
group.Add(New Label("A Label", 0, 300, 100, 0))
page.Elements.Add(group)
document.Draw(outputPath)
End Sub
Figure 1. AnchorGroup example.
TransformationGroup
The TransformationGroup class groups page elements and transforms them as a group. This class transforms entire groups of page elements and any page element placed within this group is displayed with the specified transformation.
The following example illustrates adding a rectangle and label to a group and changing the element's scale and angle.
public static void TransformationGroupExample()
{
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
TransformationGroup group1 = new TransformationGroup(100, 100, 200, 200, 30);
group1.Add(new Rectangle(0, 0, 75, 75, RgbColor.Blue, RgbColor.Blue));
group1.Add(new Label("This text is inside a TransformationGroup.", 0, 100, 300, 12));
group1.ScaleY = 2;
group1.Angle = 35;
page.Elements.Add(group1);
document.Draw(outputPath);
}
Public Shared Sub TransformationGroupExample()
Dim document As New Document()
Dim page As New Page()
document.Pages.Add(page)
Dim group1 As New TransformationGroup(100, 100, 200, 200, 30)
group1.Add(New Rectangle(0, 0, 75, 75, RgbColor.Blue, RgbColor.Blue))
group1.Add(New Label("This text is inside a TransformationGroup.", 0, 100, 300, 12))
group1.ScaleY = 2
group1.Angle = 35
page.Elements.Add(group1)
document.Draw(outputPath)
End Sub
Figure 2. TransformationGroup example.
TransparencyGroup
The TransparencyGroup class groups page elements and applies transparency to them as a group. This class applies transparency to entire groups of page elements and any page element placed within this group is displayed at the specified transparency.
The following example illustrates adding a rectangle and label to a group and changing the element's transparency.
public static void TransparencyGroupExample()
{
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
TransparencyGroup group1 = new TransparencyGroup(0.35f);
group1.Add(new Rectangle(0, 0, 75, 75, RgbColor.Blue, RgbColor.Blue));
group1.Add(new Label("This text is inside a TransparencyGroup.", 0, 100, 300, 12));
page.Elements.Add(group1);
document.Draw(outputPath);
}
Public Shared Sub TransparencyGroupExample()
Dim document As New Document()
Dim page As New Page()
document.Pages.Add(page)
Dim group1 As New TransparencyGroup(0.35F)
group1.Add(New Rectangle(0, 0, 75, 75, RgbColor.Blue, RgbColor.Blue))
group1.Add(New Label("This text is inside a TransparencyGroup.", 0, 100, 300, 12))
page.Elements.Add(group1)
document.Draw(outputPath)
End Sub
Figure 2. TransparencyGroup example.