Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.
What is this?Syndicate this content

Context Menus with TX Text Control ActiveX

This source code snippet requires TX Text Control ActiveX
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 Download [4.46 KB, 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:

  1. Private Sub TXTextControl1_MouseDown(Button As
  2. Integer, Shift As Integer, X As Single, Y As Single)
  3.  
  4. Dim nCurPos, nInputPos As Integer
  5.  
  6. If (Button = 2) Then
  7. nCurPos = TXTextControl1.SelStart
  8. nInputPos = TXTextControl1.InputPosFromPoint(X, Y)
  9. TXTextControl1.LockWindowUpdate = True
  10. TXTextControl1.SelStart = nInputPos
  11.  
  12. g_nCurTableID = TXTextControl1.TableAtInputPos
  13. g_nCurRow = TXTextControl1.TableRowAtInputPos
  14. g_nCurCol = TXTextControl1.TableColAtInputPos
  15.  
  16. TXTextControl1.SelStart = nCurPos
  17. TXTextControl1.LockWindowUpdate = False
  18.  
  19. If (g_nCurTableID <> 0 And g_nCurRow > 1) Then
  20. Form1.PopupMenu mnuPopup, 0, X, Y
  21. End If
  22. End If
  23. 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.

top

Top 10 Bestselling Product Award 2007Top 25 Publisher Product Award 2007Top 10 Bestselling Product Award 2007 in JapanTop 25 Bestselling Product Award 2006Top 25 Bestselling Publisher Award 2006Reader's Choice Award, dot.net magazin, 3rd place