使用C1PrintDocument控件 > 锚点和超链接 > 添加到用户事件的超链接 |
最后您可以在C1PreviewPane上添加一个将触发一个事件的超链接,该事件可以被您的代码逻辑捕获并处理。您应当通过C1LinkTargetUser做到这一点。以下是演示此概念的完整示例代码:
Visual Basic
Visual Basic |
拷贝代码
|
---|---|
Private Sub UserLinkSetup() ' 创建一个具有用户事件超链接的文档. 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() ' 创建预览. Dim preview As New C1.Win.C1Preview.C1PrintPreviewDialog() ' 向UserHyperlinkJump事件关联事件处理程序 AddHandler preview.PreviewPane.UserHyperlinkJump, New C1.Win.C1Preview.HyperlinkEventHandler(AddressOf Me.C1PreviewPane1_UserHyperlinkJump) ' 预览此文档. 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#
C# |
拷贝代码
|
---|---|
private void UserLinkSetup() { // 创建一个具有用户事件超链接的文档. 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(); // 创建预览. C1PrintPreviewDialog preview = new C1PrintPreviewDialog(); // 向UserHyperlinkJump事件关联事件处理程序 preview.PreviewPane.UserHyperlinkJump += new HyperlinkEventHandler(PreviewPane_UserHyperlinkJump); // 预览此文档. preview.Document = doc; preview.ShowDialog(); } private void PreviewPane_UserHyperlinkJump(object sender, HyperlinkEventArgs e) { MessageBox.Show(e.Hyperlink.UserData.ToString()); } |
该示例将在单击超链接时,弹出一个消息对话框,显示设置给超链接的UserData属性的字符串。(在本示例中,将会显示“超链接自定义用户数据示例”)。