'' This code is part of Document Solutions for Word demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
Imports System.Drawing
Imports GrapeCity.Documents.Word

'' This sample shows how to insert hyperlinks into a Word document
'' using the Range.Hyperlinks collection.
'' It adds some external hyperlinks to Web sites,
'' And also hyperlinks to bookmarks within the document.
'' This sample Is very similar to HyperlinkFields,
'' but unlike that sample uses hyperlinks collections
'' rather than HYPERLINK fields.
Public Class Hyperlinks
    Function CreateDocx() As GcWordDocument
        Dim doc = New GcWordDocument()
        Dim pars = doc.Body.Paragraphs

        '' 0. Paragraph with an external hyperlink:
        Dim p = pars.Add(
            "It is easy to add hyperlinks to document content via Range.Hyperlinks collection. " +
            "Following is a hyperlink to a web address. ")
        '' There are different Hyperlinks.Add() overloads that allow to specify
        '' different hyperlink options such as screen tips etc
        Dim hl0 = p.GetRange().Hyperlinks.Add(New Uri("http://www.google.com"), Nothing, "Click to go to www.google.com.")

        '' 1. Paragraph with an external hyperlink with its own style:
        p = pars.Add("Next is another hyperlink, this time with its own style and a custom tooltip. ")
        Dim hl1 = p.GetRange().Hyperlinks.Add(New Uri("https://www.grapecity.com/en/"), Nothing, "Click to go to www.grapecity.com.", "Click to open GrapeCity web page")

        '' 2. Link to a bookmark within the document:
        '' We add bookmarks at the top and bottom of the document,
        '' and set up links to jump between them.
        Dim bmkTop = "BookmarkTop"
        Dim bmkBot = "BookmarkEnd"
        p = pars.Add(
                "Hyperlinks can also point to locations within the document. " +
                "We add some filler paragraphs below, followed by a paragraph " +
                $"with a bookmark named '{bmkBot}' attached to it. " +
                "The next hyperlink jumps to that bookmark. ")
        '' Attach a bookmark to this paragraph so we can jump back here:
        '' A hyperlink to a bookmark
        Dim hl2 = p.GetRange().Hyperlinks.Add($"{bmkBot}", $"Click to jump to {bmkBot} at the end of the document.", $"Jumo to {bmkBot}")
        hl2.GetRange().Runs.First.Style = doc.Styles(BuiltInStyleId.FollowedHyperlink)

        '' Add filler, bookmarked paragraph after it, and
        '' a link to jump back:
        For i = 0 To 99
            pars.Add($"Filler paragraph {i}.")
        Dim pb = pars.Add($"{bmkBot} points here. ")
        Dim hl3 = pb.GetRange().Hyperlinks.Add($"{bmkTop}", $"Jump back to {bmkTop}.", $"Jumo to {bmkTop}")
        hl3.GetRange().Runs.First.Style = doc.Styles(BuiltInStyleId.FollowedHyperlink)

        '' Done:
        Return doc
    End Function
End Class