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

Context Menus with TX Text Control .NET

This source code snippet requires TX Text Control .NET
Author:TX Text Control Support Department
Language:Visual Basic
Version:1.0
Released:August 04, 2004
Last modified:January 11, 2008
Requirements:TX Text Control .NET with Visual Basic .NET
Download code:tx_context_menu.zip Download [9.28 KB, ZIP]
Click to enlarge

Context Menus with TX Text Control .NET

A context menu is a very helpful feature to provide end users with information or menu options at a specific text position.

For example, a context menu for adding additional field information could be shown, but only if the user clicks on a field.

This week, we would like to show you how to create a very simple context menu.

When an end user right clicks, a menu will be displayed that offer the actions Cut, Copy and Paste. Only the possible menu entries will be shown.

For example, a Copy menu will be only shown, if a part of the text has been selected by the user.

  1. Private Sub TextControl1_MouseUp(ByVal sender As Object, ByVal_
  2. e As System.Windows.Forms.MouseEventArgs) Handles TextControl1.MouseUp
  3.  
  4. Dim pos As System.Drawing.Point
  5.  
  6. If e.Button = MouseButtons.Right Then
  7. MenuItem3.Visible = TextControl1.CanCopy
  8. MenuItem4.Visible = TextControl1.CanPaste
  9.  
  10. If TextControl1.Selection.Length = 0 Then
  11. MenuItem2.Visible = False
  12. Else
  13. MenuItem2.Visible = True
  14. End If
  15.  
  16. pos.X = e.X
  17. pos.Y = e.Y
  18. ContextMenu1.Show(TextControl1, pos)
  19. End If
  20.  
  21. End Sub

We use the TX Text Control MouseUp event to intercept the end user's right mouse click. The Visible property of the different menu entries can be used to hide functionality that is currently not possible. Finally, the context menu will be shown at the X and Y position returned by the MouseUp event.

At least TX Text Control .NET trial version and Visual Studio .NET is required to test this sample.

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