Finally, in this step, jumps to other documents and jumps to targets in these documents are added.
1. An Enhanced Dialog Box for Displaying and Selecting Targets:
Again the Hypertext Link dialog box is extended to choose an external file. A Choose File... button is placed on the form that triggers a common dialog.
After the user has chosen a file, its name is displayed in the text box and the file is searched for internal targets:
[Visual Basic 6] Private Sub CheckFileForTargets(file As String) tx(1).LoadSaveAttribute(txEnableLinks) = True tx(1).Load file, 0, 4 FillListboxWithTargets (1) optSelFile.Value = True loadedFile = file End Sub
For this purpose the file is loaded in a second, invisible Text Control. Then the FieldNext method is used as in step 3 to list all targets.
2. Jumping to an External Target:
To implement the jump to an external link, the code added to the FieldLinkClicked event in step 3 must be extended. The following code does not handle jumps to internet addresses, it only implements jumps to targets in other files. To separate a file from a name of a target, Text Control uses the '#' character. The following code separates the file name and the target's name, loads the file with the Load method and jumps to the target with the FieldGoto method:
[Visual Basic 6] ElseIf FieldType = txFieldExternalLink Then 'This sample does not feature links to www sites, 'so exit sub If Left(TypeData, 7) = "http://" Then Exit Sub End If TXTextControl1.LoadSaveAttribute(txEnableLinks) = True pos = InStr(TypeData, "#") 'File name includes an internal link If pos >= 0 Then 'Ask the user to save changes, if any If bDocDirty Then ret = MsgBox("Save changes?", vbYesNoCancel, _ "Question") If ret = vbYes Then mnuFile_SaveAs_Click ElseIf ret = vbCancel Then Exit Sub End If End If 'Extract file name & path from full path str = Left(TypeData, pos - 1) TXTextControl1.Load str, 0, 4 'Extract file position from full path str = Mid(TypeData, pos + 1) TXTextControl1.FieldGoto txFieldLinkTarget, str Else 'File name doesn't include an internal link TXTextControl1.Load TypeData, 0, 4 End If End If
3. Loading and Saving Files containing Hypertext Links:
When an HTML, RTF or Microsoft Word document is loaded, Text Control must convert containing hypertext links to appropriate marked text fields as described above. To perform this, a programmer must set the LoadSaveAttribute (txEnableLinks) before using the Load method. Otherwise hypertext links and target fields are not converted. When a document is saved, marked text fields that represent hypertext links, are always converted to the appropriate format.
If Text Control's proprietary format is used, setting LoadSaveAttribute is not necessary.
More information about hypertext links and a list of all properties, methods and events that can be used with marked text fields, can be found in the chapter Technical Articles - Marked Text Fields - Special Types of Marked Text Fields.