| Skype: | TextControlSupport | |
| Orders: | 877-462-4772 |

| Author: | TX Text Control Support Department |
| Language: | Visual Basic |
| Version: | 1.1 |
| Released: | June 14, 2002 |
| Last modified: | January 11, 2008 |
| Requirements: | TX Text Control ActiveX with Visual Basic 6.0 |
| Download code: | context_menu.zip |
We have received several e-mails this week from users wanting to have a context menu pop up when they click into a TX Text Control window. In this newsletter, we are going to show you this can be achieved.
In the sample program, a quotation is loaded when the TX Text Control program starts. This quotation contains a table in which we want the context menu to appear. When the user clicks the table with the right mouse, the table id and the column in which the user clicked are calculated. The popup menu then appears and allows the user to add a row above or below the clicked row.
How can this be done? First of all, we need the position in the document where the user clicked. This can be achieved easily by calling InputPosFromPoint. Then we use LockWindowUpdate to prevent the user from seeing what we are about to do.
We set the cursor position to the value we just received and call TableAtInputPos to check if there is a table. Also, we use TableRowAtInputPos and TableColAtInputPos to determine the column and row in the table. After that, we restore the input position and unlock the window update.
Now, we can show the popup menu...
Here is the code:
Private Sub TXTextControl1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim nCurPos, nInputPos As Integer If (Button = 2) Then nCurPos = TXTextControl1.SelStart nInputPos = TXTextControl1.InputPosFromPoint(X, Y) TXTextControl1.LockWindowUpdate = True TXTextControl1.SelStart = nInputPos g_nCurTableID = TXTextControl1.TableAtInputPos g_nCurRow = TXTextControl1.TableRowAtInputPos g_nCurCol = TXTextControl1.TableColAtInputPos TXTextControl1.SelStart = nCurPos TXTextControl1.LockWindowUpdate = False If (g_nCurTableID <> 0 And g_nCurRow > 1) Then Form1.PopupMenu mnuPopup, 0, X, Y End If End If End Sub
Of course, there are many more possibilities to use context menus in this way. For example, you could dynamically add a list of products to the popup menu and let the user add these to the table. Or whatever you can think off.