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 Samples\vb6\Field1 sample source directory.
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. There are two Text Controls on the form, one of which is used as a normal text window (TXTextControl1), the other one as a pop-up window (TXTextControl2).
The following code is executed when the menu item is clicked on:
[Visual Basic 6] Private Sub mnuInsertField_Click () TXTextControl1.FieldInsert "--------" End Sub
This inserts a field at the current caret position. If you move the cursor over the field, Text Control changes the mouse pointer to an upward pointing arrow to indicate that there is something to click on.
If you click on the field, the application receives a FieldClicked event, to which it responds by popping up a window which displays the field number.
Only four lines of code are required for this:
[Visual Basic 6] Private Sub TXTextControl1_FieldClicked(ByVal FieldIndex As Integer) TXTextControl1.FieldCurrent = FieldIndex TXTextControl2.Text = "This is field no. " & FieldIndex _ & ". Its text is: " & TXTextControl1.FieldText TXTextControl2.Move TXTextControl1.FieldPosX, _ TXTextControl1.FieldPosY TXTextControl2.ZOrder End Sub
The first line selects the Marked Text Field which has been clicked on. Line 2 builds the string that is to be displayed in the pop-up window. Line 3 moves the pop-up window, which is initially hidden behind the text window, to the position of the marked text field. Line 4 puts the pop-up window in front of the text window to make it visible. When the mouse button is released, the text window is moved to the front again:
[Visual Basic 6] Private Sub TXTextControl1_MouseUp(Button As Integer, _ Shift As Integer, X As Single, Y As Single) TXTextControl1.ZOrder End Sub