Hyperlinks

The C1RichTextBox supports hyperlinks. As in regular HTML documents, this feature allows you to make certain parts of the document active. When the user clicks them, the application receives a notification and takes some action.

The code below shows how you can create a hyperlink:

      Visual Basic

      C#

The code starts by assigning some text to the C1RichTextBox. Next, it selects the word "hyperlink" and calls the MakeHyperlink method to make it a hyperlink. The parameter is a URI that is assigned to the new hyperlink's NavigateUri property.

Then, the code sets the NavigationMode property to determine how the C1RichTextBox should handle the mouse over hyperlinks. The default behavior is like that of Microsoft Word and Visual Studio: moving the mouse over a hyperlink while holding down the CTRL key causes the cursor to turn into a hand, and clicking while the CTRL key is pressed fires the RequestNavigate event. This allows users to edit the hyperlink text as they would edit regular text.

TheRequestNavigate event handler is responsible for handling the hyperlink navigation. In many cases this requires opening a new browser window and navigating to a different URL. This is illustrated below:

      Visual Basic

      C#

Note that hyperlink actions are not restricted to URI navigation. You could define a set of custom URI actions to be used as commands within your application. The custom URIs would be parsed and handled by the RequestNavigate handler. For example, the code below uses hyperlinks to show message boxes:

      Visual Basic

      C#

The only change in the MakeHyperlink code is the line that creates the URI. The RequestNavigate handler uses the URI members to parse the command and argument. You could use this technique to create documents with embedded menus for example.

Note that the CreateHyperlink method is just a quick and easy way to turn an existing part of a document into a hyperlink. You can also create hyperlinks by adding C1Hyperlink elements to C1Document objects. This is described in later sections.


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.