Adding a Hyperlink to an Anchor within the Same Document
To link one part of your document to another, you have to do two things:
• Mark the location (called an anchor) where you want the link to point.
• Add a link to that location (a hyperlink) to another part of the document (you can have several hyperlinks pointing to the same anchor, of course).
To create an anchor on a render object, you can add an element (of the type C1Anchor) to the Anchors collection of that render object. For example, if rt is a RenderTable you can write:
rt.Anchors.Add(New C1.C1Preview.C1Anchor("anchor1"))
• C#
rt.Anchors.Add(new C1Anchor("anchor1"));
This will define an anchor with the name anchor1 (the name used to reference the anchor) on the render table.
To link another render object, for example a RenderText, to that anchor, you can write:
Dim rtxt As New C1.C1Preview.RenderText()
rtxt.Text = "Link to anchor1"
rtxt.Hyperlink = New C1.C1Preview.C1Hyperlink("anchor1")
• C#
RenderText rtxt = new RenderText();
rtxt.Text = "Link to anchor1";
rtxt.Hyperlink = new C1Hyperlink("anchor1");
Of course, you must add both involved render objects (the one containing the anchor, and the one with the hyperlink) to the document.
Hyperlink is a property of the RenderObject class, which is the base class for all render objects, so in exactly the same manner as shown above, any render object may be turned into a hyperlink by setting that property.
|