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

Adding tooltips to marked text fields

This source code snippet requires TX Text Control ActiveX
Author:TX Text Control Support Department
Language:Visual Basic 6.0
Version:1.0
Released:October 19, 2004
Last modified:January 11, 2008
Requirements:TX Text Control ActiveX with Visual Basic 6.0
Download code:tx_sample_activex_tooltip.zip Download [33.77 KB, ZIP]

Add tooltips to your marked text fields

Click to enlarge

This illustrates how to display a tool tip when the end user moves his/her mouse over a marked text field. This is particularly helpful to display special information or functions of a field for the end user.

For example: A hyperlink will be only followed, if the user presses CTRL and clicks on the link. This functionality needs to be communicated to the end user: A tool tip is a perfect means to transfer this information.

TX Text Control does not have an event that is fired, when the mouse moves over a field. The FieldSetCursor event - normally used to change the cursor style - can, however, be utilized for this purpose.

A second TX Text Control with a yellow background is used for the tool tip itself. On the FieldSetCursor event, the text of the tool tip is specified and a timer is started.

A timer is necessary to hide the tool tip window when it is no longer required. The result is that the tool tip will disappear, if the mouse cursor leaves the field position.

  1. Private Sub TXTextControl1_FieldSetCursor(ByVal FieldId As Integer, _
  2. MousePointer As Integer)
  3. Dim TextExtent() As Long
  4. MousePointer = 12
  5. TXTextControl1.FieldCurrent = FieldId
  6. TXTextControl2.Text = TXTextControl1.FieldTypeData (TXTextControl1.FieldCurrent) + vbCrLf
  7. TXTextControl2.SelStart = -1
  8. TXTextControl2.SelText = "CTRL + click to follow link"
  9. Timer1.Interval = 100
  10. End Sub
  11.  
  12. Private Sub Timer1_Timer()
  13. TXTextControl2.ZOrder 1
  14. Timer1.Interval = 0
  15. End Sub

Now, we just need a global flag to specify whether the CTRL key is pressed or not. This global variable will be used in the FieldClicked event. If the user presses the CTRL key and clicks the field, the default browser will be opened with the current hyperlink.

  1. Private Sub TXTextControl1_FieldClicked(ByVal FieldId As Integer)
  2. If CTRL_flag = True Then
  3. Result = ShellExecute(Me.hwnd, "Open", TXTextControl1.FieldTypeData _
  4. (TXTextControl1.FieldCurrent),"", App.Path, 1)
  5. CTRL_flag = False
  6. End If
  7. End Sub

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