A Simple Example

This first sample program will show you how fields are created and what happens when they are clicked on. The code shown here is contained in the following directories:

The program consists of a form with just one menu item, Insert Field!, with an exclamation mark to say that clicking on this item will cause an immediate action instead of dropping a menu.

The following code is executed when the menu item is clicked on:

[C#]
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
	TXTextControl.TextField NewField = new TXTextControl.TextField();

	// Insert a new field and increase field ID
	NewField.Text = "[TextField" + fieldID.ToString() + "]";
	NewField.ID = fieldID;
	NewField.DoubledInputPosition = true;
	fieldID += 1;

	textControl1.TextFields.Add(NewField);
}
[Visual Basic]
Private Sub MenuItem_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
	Dim NewField As New TXTextControl.TextField()

	' Insert a new field and increase field ID
	NewField.Text = "[TextField" & fieldID.ToString() & "]"
	NewField.ID = fieldID
	NewField.DoubledInputPosition = True
	fieldID += 1

	textControl1.TextFields.Add(NewField)
End Sub

This inserts a field at the current caret position and assigns a unique number to the fields ID property. If you move the cursor over the field, Text Control changes the mouse pointer to a hand cursor to indicate that there is something to click on.

If you click on the field, the application receives a TextFieldClicked event, to which it responds by popping up a window which displays the field number.

Only two lines of code are required for this:

[C#]
private void textControl1_TextFieldClicked(object sender, TXTextControl.TextFieldEventArgs e)
{
	MessageBox.Show("Field " + fieldID.ToString() + " has been clicked.");
}
[Visual Basic]
Private Sub textControl1_TextFieldClicked(ByVal sender As Object, ByVal e As TXTextControl.TextFieldEventArgs)
	MessageBox.Show("Field " & fieldID.ToString() & " has been clicked.")
End Sub

Next >>