Step 1: Inserting a Hypertext Link

In this first sample program, a hypertext link will be inserted in a text document. The document is then saved as an HTML file so that it can be displayed in a browser. This is what the sample program looks like:

To insert a hypertext link, we first need to create a HypertextLink object. The text to be displayed in the document ("Text Control Web Site") and the information about where to link to ("http://www.textcontrol.com") are passed as parameters to the constructor. The object that is thus created is then inserted at the current input position by adding it to a Text Control's HypertextLinks collection.

[C#]
private void cmdInsertHyperlink_Click(object sender, System.EventArgs e)
{
    // Create a HypertextLink object
    TXTextControl.HypertextLink MyLink = 
        new TXTextControl.HypertextLink(
        "Text Control Web Site", 
        "http://www.textcontrol.com");
    // Insert the hyperlink into the document
    textControl1.HypertextLinks.Add(MyLink);
}
[Visual Basic]
Private Sub cmdInsertHyperlink_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles cmdInsertHyperlink.Click
    ' Create a HypertextLink object
    Dim MyLink As New TXTextControl.HypertextLink( _
        "Text Control Web Site", _
        "http://www.textcontrol.com")
    ' Insert the hyperlink into the document
    TextControl1.HypertextLinks.Add(MyLink)
End Sub

Note that this first sample program does not handle the Click events, so clicking on a hypertext link in the TX Text Control will have no effect. Also, the link does not yet have the typical blue and underlined formatting style. Click events and formatting will be covered in Step 2.

The TextControl.Save method is used to save the document as an HTML file:

[C#]
private void cmdSaveAs_Click(object sender, System.EventArgs e)
{
    textControl1.Save(TXTextControl.StreamType.HTMLFormat);
}
[Visual Basic]
Private Sub cmdSaveAs_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles cmdSaveAs.Click
    TextControl1.Save(TXTextControl.StreamType.HTMLFormat)
End Sub
[Delphi]
procedure Form1.cmdSaveAs_Click(sender: System.Object; 
    e: System.EventArgs);
begin
    TextControl1.Save(TXTextControl.StreamType.HTMLFormat);
end;

When the HTML file is opened in a web browser, the hypertext link is displayed as specified in your browser's settings.

Clicking on the link will take you to the TX Text Control web site.