Identifiers and Names for Text Fields and Hypertext Links

Technical Articles > Using Text Fields and Hypertext Links

A Text Control can manage an identfier and/or a name for each text field. These data can be specified with the TextField.ID and TextField.Name properties. For example, when a Text Control is used to show the contents of a database, a marked text field can be created for each database field. The database's field names can then be related to the text fields using the TextField.Name property. If something then happens with the field and an event occurs, the TextField.Name property informs, which field has caused the event. The following code inserts a field presenting a price:

TextField newField = new TextField("$ 22.45");
newField.Name = "Price";
[Visual Basic]
Dim NewField As New TextField("$ 22.45")
NewField.Name = "Price"

When a marked text field is copied via the clipboard or saved to a file, the id and/or name belonging to the field are also copied or saved. If a field is copied via the clipboard, a TextControl.TextFieldCreated event occurs so that the programmer has the opportunity to change the id and/or name to avoid multiple occurrences. The following code shows an installed event handler for the TextFieldCreated event. This event occurs after the end-user has copied via the clipboard the field created above. The Name property of the created field is changed so that other code can distinguish between the two fields:

        += new TextFieldEventHandler(textControl1_TextFieldCreated);
private void textControl1_TextFieldCreated(object sender, TextFieldEventArgs e) {
    if (e.TextField.Name == "Price") {
        e.TextField.Name = "Copy of Price";
[Visual Basic]
Private Sub TextControl1_TextFieldCreated(ByVal sender As Object, _
        ByVal e As TextFieldEventArgs) Handles TextControl1.TextFieldCreated
    If e.TextField.Name = "Price" Then
        e.TextField.Name = "Copy of Price"
    End If
End Sub

Any string data can be assigned to the Name property. The number of characters is not limited so that even a large text can be related to a field.