This message contains graphics. If you do not see the graphics: Graphic Version.
 
A Closer Look at Context Menus, Save Over USD 800 on an MSDN Universal Sub

A Closer Look at Context Menus in TX Text Control

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.

As every you can download the source code to this example.

Save Over USD 800 on an MSDN Universal Subscription

VBxtras has acquired limited quantities of MSDN Universal Subscriptions that we can make available at rock-bottom prices. MSDN Universal delivers all Microsoft development tools (including Visual Studio .NET Enterprise Architect), five core .NET Enterprise Servers, and the technical resources needed to build XML Web services and applications. A new subscription is just $1924, plus you will receive a $300 rebate from Microsoft if you select the DVD media option.

For details on this offer, please visit the VBxtras website at:

http://www.vbxtras.com/


Best regards

The Newsletter Team

Text Control GmbH respects your online time and privacy. We only send this newsletter to TX Text Control customers and people who have signed up to receive it. However, if you would prefer not to receive future issues of the newsletter, you may unsubscribe at any time. If you received this newsletter forwarded from a colleague or friend, you may wish to subscribe directly.

Sent to: N/A.

Imprint | Unsubscribe | Subscribe

© 2002 Text Control GmbH. All Rights Reserved.