Back to Devexpress

HyperlinkCollection Interface

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-b599c06b.md

latest5.5 KB
Original Source

HyperlinkCollection Interface

An interface that defines a collection of Hyperlink objects.

Namespace : DevExpress.XtraRichEdit.API.Native

Assembly : DevExpress.RichEdit.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
[ComVisible(true)]
public interface HyperlinkCollection :
    ReadOnlyHyperlinkCollection,
    ISimpleCollection<Hyperlink>,
    IEnumerable<Hyperlink>,
    IEnumerable,
    ICollection
vb
<ComVisible(True)>
Public Interface HyperlinkCollection
    Inherits ReadOnlyHyperlinkCollection,
             ISimpleCollection(Of Hyperlink),
             IEnumerable(Of Hyperlink),
             IEnumerable,
             ICollection

The following members return HyperlinkCollection objects:

Remarks

Use the HyperlinkCollection.Create method to add a new hyperlink to the collection.

The code snippet below finds a specific range in the document and converts it to a hyperlink with the specified URI and tooltip:

csharp
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;

using (var wordProcessor = new RichEditDocumentServer())
{
  wordProcessor.LoadDocument("Documents//Document.docx");
  Document document = wordProcessor.Document;

  // Find a specific text string
  DocumentRange[] foundRanges =
          document.FindAll("DevExpress WinForms Rich Text Editor",
  SearchOptions.CaseSensitive);

  if (foundRanges.Length > 0)
  {
      // Convert the found range to a hyperlink
      Hyperlink hyperlink = document.Hyperlinks.Create(foundRanges[0]);

      // Specify the URI and the tooltip
      hyperlink.NavigateUri =
           "https://www.devexpress.com/Products/NET/Controls/WinForms/Rich_Editor/";
      hyperlink.ToolTip = "WinForms Rich Text Editor";
  }
}
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native

Using wordProcessor = New RichEditDocumentServer()
  wordProcessor.LoadDocument("Documents//Document.docx")
  Dim document As Document = wordProcessor.Document

  ' Find a specific text string
  Dim foundRanges() As DocumentRange =
       document.FindAll("DevExpress WinForms Rich Text Editor", SearchOptions.CaseSensitive)

  If foundRanges.Length > 0 Then
      ' Convert the found range to a hyperlink
      Dim hyperlink As Hyperlink = document.Hyperlinks.Create(foundRanges(0))

      ' Specify the URI and the tooltip
      hyperlink.NavigateUri =
           "https://www.devexpress.com/Products/NET/Controls/WinForms/Rich_Editor/"
      hyperlink.ToolTip = "WinForms Rich Text Editor"
  End If
End Using

Note

The hyperlink attached to a shape is not added to the HyperlinkCollection. Check the Shape.Hyperlink property to retrieve the hyperlink.

To remove an existing hyperlink, use the HyperlinkCollection.Remove method.

The code sample below locates and removes all hyperlinks in the first section:

csharp
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;

using (var wordProcessor = new RichEditDocumentServer())
{
    // Load a document
    wordProcessor.LoadDocument("Documents//Document.docx");
    Document document = wordProcessor.Document;

    // Obtain all hyperlinks in the first section
    var hyperlinks = document.Hyperlinks.Get(document.Sections[0].Range);
    if (hyperlinks != null)
    {
        // Remove all hyperlinks
        foreach (Hyperlink hyperlink in hyperlinks)
        {
            document.Hyperlinks.Remove(hyperlink);
        }
    }
}
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native

Using wordProcessor = New RichEditDocumentServer()
    ' Load a document
    wordProcessor.LoadDocument("Documents//Document.docx")
    Dim document As Document = wordProcessor.Document

    ' Obtain all hyperlinks in the first section
    Dim hyperlinks = document.Hyperlinks.Get(document.Sections(0).Range)
    If hyperlinks IsNot Nothing Then
        ' Remove all hyperlinks
        For Each hyperlink As Hyperlink In hyperlinks
            document.Hyperlinks.Remove(hyperlink)
        Next hyperlink
    End If
End Using

See Also

HyperlinkCollection Members

Hyperlinks

Create

DevExpress.XtraRichEdit.API.Native Namespace