ComponentOne Reports for WinForms Designer Edition: ComponentOne Reports for WinForms > Working with C1PrintDocument > Expressions, Scripts, Tags > Tags

Tags

Tags are closely related to expressions. In fact, tags are variables that can be used in expressions, or simply as expressions. In the simplest case, tags allow you to use a placeholder where you want to insert a certain string but do not know the value of that string yet. The typical example of a tag is the page number – you want to print the page number but do not know yet what it is going to be or realize it may change when the document is regenerated.

A tag has two main properties: Name and Value. The name is used to identify the tag, while the value is what the tag is replaced with.

C1PrintDocument provides two kinds of tags: predefined and custom. Predefined tags are:

      [PageNo] – replaced with the current page number.

      [PageCount] – replaced with the total number of pages.

      [PageX] – replaced with the current horizontal page number.

      [PageXCount] – replaced with the total number of horizontal pages.

      [PageY] – replaced with the current vertical page number (if there are no horizontal pages, this is equivalent to [PageNo]).

      [PageYCount] – replaced with the total number of vertical pages (if there are no horizontal pages, this is equivalent to [PageCount]).

Custom tags are stored in the Tags collection of the document. To add a tag to that collection, you may use the following code:

      Visual Basic

doc.Tags.Add(New C1.C1Preview.Tag("tag1", "tag value"))

      C#

doc.Tags.Add(new C1.C1Preview.Tag("tag1", "tag value"));

The value of the tag may be left unspecified when the tag is created, and may be specified at some point later (even after that tag was used in the document).

To use a tag, insert its name in square brackets in the text where you want the tag value to appear, for example, like this:

      Visual Basic

Dim rt As New C1.C1Preview.RenderText()

rt.Text = "The value of tag1 will appear here: [tag1]."

      C#

RenderText rt = new RenderText();

Rt.Text = "The value of tag1 will appear here: [tag1].";


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.