Adding a Hyperlink to a User Event
Finally, you may add a hyperlink that will fire an event on the C1PreviewPane, to be handled by your code. For this, C1LinkTargetUser should be used. Here is a complete example illustrating the concept:
Private Sub UserLinkSetup()
' Make document with a user hyperlink.
Dim doc As New C1.C1Preview.C1PrintDocument
Dim rt As New C1.C1Preview.RenderText("Click this to show message box...")
Dim linkTarget As C1.C1Preview.C1LinkTarget = New C1.C1Preview.C1LinkTargetUser
rt.Hyperlink = New C1.C1Preview.C1Hyperlink(linkTarget)
rt.Hyperlink.UserData = "My hyperlnk user data"
doc.Body.Children.Add(rt)
doc.Generate()
' Create the preview.
Dim preview As New C1.Win.C1Preview.C1PrintPreviewDialog()
' Attach an event handler to the UserHyperlinkJump event.
AddHandler preview.PreviewPane.UserHyperlinkJump, New C1.Win.C1Preview.HyperlinkEventHandler(AddressOf Me.C1PreviewPane1_UserHyperlinkJump)
' Preview the document.
preview.Document = doc
preview.ShowDialog()End Sub
Private Sub C1PreviewPane1_UserHyperlinkJump(ByVal sender As Object, ByVal e As C1.Win.C1Preview.HyperlinkEventArgs) Handles C1PreviewPane1.UserHyperlinkJump
MessageBox.Show(e.Hyperlink.UserData.ToString())
End Sub
• C#
private void UserLinkSetup()
{
// Make document with a user hyperlink.
C1PrintDocument doc = new C1PrintDocument();
RenderText rt = new RenderText("Click this to show message box...");
C1LinkTarget linkTarget = new C1LinkTargetUser();
rt.Hyperlink = new C1Hyperlink(linkTarget);
rt.Hyperlink.UserData = "My hyperlnk user data";
doc.Body.Children.Add(rt);
doc.Generate();
// Create the preview.
C1PrintPreviewDialog preview = new C1PrintPreviewDialog();
// Attach an event handler to the UserHyperlinkJump event.
preview.PreviewPane.UserHyperlinkJump += new HyperlinkEventHandler(PreviewPane_UserHyperlinkJump);
// Preview the document.
preview.Document = doc;
preview.ShowDialog();
}
private void PreviewPane_UserHyperlinkJump(object sender, HyperlinkEventArgs e)
{
MessageBox.Show(e.Hyperlink.UserData.ToString());
}
This example will show the message box with the string that was assigned to the UserData property of the hyperlink when the hyperlink is clicked (in this case, "My hyperlink user data").
|