Use this constructor when creating a bookmark for the report's document map.
This example illustrates how to make Print Preview display a Document Map listing all bookmarks assigned to a Document's elements.
The following code adds five Bricks to the Detail section of a document and then assigns bookmarks to each brick.
Note that the Document Map button is automatically enabled in Print Preview when a displayed document has any bookmarks.
Form1.cs |
using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraPrinting;
using DevExpress.XtraPrinting.Native;
private void button1_Click(object sender, EventArgs e) {
PrintingSystem ps = new PrintingSystem();
Link link = new Link(ps);
link.CreateDetailArea += new CreateAreaEventHandler(OnDocumentCreated);
link.CreateDocument();
CreateDocumentMap(ps.Document);
link.ShowPreview();
link.CreateDetailArea -= new CreateAreaEventHandler(OnDocumentCreated);
}
private void OnDocumentCreated(object sender, CreateAreaEventArgs e) {
for (int i = 0; i < 5; i++) {
TextBrick brick = new TextBrick();
brick.Text = "Item #" + (i + 1).ToString();
brick.BackColor = Color.Yellow;
brick.Rect = new Rectangle(10, i * 100, 100, 50);
e.Graph.DrawBrick(brick, brick.Rect);
}
}
private void CreateDocumentMap(Document document) {
BrickPagePairCollection pairs = new BrickPagePairCollection();
DocumentBrickEnumerator en = new DocumentBrickEnumerator(document);
while (en.MoveNext()) {
pairs.Add(BrickPagePair.Create(en.Brick, en.Page));
}
foreach (BrickPagePair pair in pairs) {
Page page = document.Pages[pair.PageIndex];
Brick brick = page.GetBrickByIndices(pair.BrickIndices) as Brick;
string BrickText = ((TextBrick)brick).Text;
BookmarkNode mapNode = new BookmarkNode(BrickText, brick, page);
document.BookmarkNodes.Add(mapNode);
}
}
|
Form1.vb |
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraPrinting.Native
' ...
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' Create a new Printing System.
Dim ps As New PrintingSystem()
' Create a new link and add a handler to its CreateDetailArea event.
Dim link As New Link(ps)
AddHandler link.CreateDetailArea, AddressOf OnDocumentCreated
' Create a document for the link.
link.CreateDocument()
' Create a document's map.
CreateDocumentMap(ps.Document)
' Show the report's preview.
link.ShowPreview()
End Sub
Private Sub OnDocumentCreated(ByVal sender As Object, ByVal e As CreateAreaEventArgs)
' Draw 5 bricks on a document.
For i As Integer = 0 To 4
Dim brick As New TextBrick()
brick.Text = "Item #" & (i + 1).ToString()
brick.BackColor = Color.Yellow
brick.Rect = New Rectangle(10, i * 100, 100, 50)
e.Graph.DrawBrick(brick, brick.Rect)
Next i
End Sub
Private Sub CreateDocumentMap(ByVal document As Document)
' Create a collection of 'Page and Brick' pairs.
Dim Pairs As New BrickPagePairCollection()
' Create an enumerator of all document bricks.
Dim en As New DocumentBrickEnumerator(document)
' Add the 'Brick-Page' pairs for all document bricks.
While en.MoveNext()
Pairs.Add(BrickPagePair.Create(en.Brick, en.Page))
End While
' Add bookmarks for all pairs to the document's map.
Dim Pair As BrickPagePair
For Each Pair In Pairs
Dim page As Page = document.Pages(Pair.PageIndex)
Dim brick As Brick = CType(page.GetBrickByIndices(Pair.BrickIndices), Brick)
Dim BrickText As String = CType(brick, TextBrick).Text
Dim mapNode As New BookmarkNode(BrickText, brick, page)
document.BookmarkNodes.Add(mapNode)
Next
End Sub
|