Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I create ToolTipText with multiple lines?

Tips -N- Tricks

How can I create ToolTipText with multiple lines?

by  ChrisRChamberlain  Posted    (Edited  )
ToolTipText remains one of the most efficient means of showing information about a control in VFP.

However should you wish to display more than the average amount of data, you have the visual problem of it being displayed on a single line, and ultimately a string length limit of 127 characters.

The following code demonstrates how, in VFP 7.0, you can split the information over up to four lines and also include blank lines if needed.

By increasing the number of parameters/lines in the example code, you can utilise up to 256 characters, (including spaces), for the display.

Add a label to your form and rename it [color blue].lblToolTipText[/color]

Change the following properties of the label
[color blue]
.FontName = [MS Sans Serif]
.FontSize = 9
.Visible = .F.
[/color]
In the [color blue].MouseEnter()[/color] event of the control(s) for which you wish to display ToolTipText put :-
[color blue]
lcLine1 = [This is the first line to display]
lcLine2 = [This is just another line]
lcLine3 = [And one more for luck!]
lcLine4 = [And yet another one for luck!]

THISFORM.mToolTipText(nXCoord,nYCoord,lcLine1,lcLine2,lcLine3,lcLine4)[/color]

It isn't necessary to pass any more than 3 parameters to the method [color blue]THISFORM.mToolTipText()[/color], so you only need create as many lines as you require.

In the [color blue].MouseLeave()[/color] event of the control(s) put :-
[color blue]
THISFORM.lblToolTipText.Visible = .F.[/color]

Remove any existing ToolTipText for the control(s).

Create a new form method called [color blue].mToolTipText()[/color] and put :-
[color blue]
LPARAMETERS ;
[tab]tnLeft ,;
[tab]tnTop ,;
[tab]tcLine1 ,;
[tab]tcLine2 ,;
[tab]tcLine3 ,;
[tab]tcLine4

LOCAL lcCaption ,;
[tab]lcLine1 ,;
[tab]lcLine2 ,;
[tab]lcLine3 ,;
[tab]lcLine4 ,;
[tab]lnHeight ,;
[tab]lnSize ,;
[tab]lnWidth

lnSize = FONTMETRIC(6,[MS Sans Serif],9)

WITH THIS
[tab]DO CASE
[tab]CASE PCOUNT() = 3
[tab][tab]lcLine1 = [ ] ;
[tab][tab][tab]+ ALLTRIM(tcLine1) ;
[tab][tab][tab]+ [ ]
[tab][tab]lnLength = TXTWIDTH(lcLine1,[MS Sans Serif],9)
[tab][tab]lcCaption = lcLine1
[tab][tab]lnHeight = 15

[tab]CASE PCOUNT() = 4
[tab][tab]lcLine1 = [ ] ;
[tab][tab][tab]+ ALLTRIM(tcLine1);
[tab][tab][tab]+ [ ]
[tab][tab]lnLength = TXTWIDTH(lcLine1,[MS Sans Serif],9)
[tab][tab]lcLine2 = [ ] ;
[tab][tab][tab]+ ALLTRIM(tcLine2) ;
[tab][tab][tab]+ [ ]
[tab][tab]lnLine2 = TXTWIDTH(lcLine2,[MS Sans Serif],9)

[tab][tab]IF lnLine2 > lnLength
[tab][tab][tab]lnLength = lnLine2
[tab][tab]ENDI

[tab][tab]lcCaption = lcLine1 ;
[tab][tab][tab]+ CHR(13) ;
[tab][tab][tab]+ lcLine2
[tab][tab]lnHeight = 29

[tab]CASE PCOUNT() = 5
[tab][tab]lcLine1 = [ ] ;
[tab][tab][tab]+ ALLTRIM(tcLine1) ;
[tab][tab][tab]+ [ ]
[tab][tab]lnLength = TXTWIDTH(lcLine1,[MS Sans Serif],9)

[tab][tab]lcLine2 = [ ] ;
[tab][tab][tab]+ ALLTRIM(tcLine2) ;
[tab][tab][tab]+ [ ]
[tab][tab]lnLine2 = TXTWIDTH(lcLine2,[MS Sans Serif],9)

[tab][tab]IF lnLine2 > lnLength
[tab][tab][tab]lnLength = lnLine2
[tab][tab]ENDI

[tab][tab]lcLine3 = [ ] ;
[tab][tab][tab]+ ALLTRIM(tcLine3) ;
[tab][tab][tab]+ [ ]
[tab][tab]lnLine3 = TXTWIDTH(lcLine3,[MS Sans Serif],9)

[tab][tab]IF lnLine3 > lnLength
[tab][tab][tab]lnLength = lnLine3
[tab][tab]ENDI

[tab][tab]lcCaption = lcLine1 ;
[tab][tab][tab]+ CHR(13) ;
[tab][tab][tab]+ lcLine2 ;
[tab][tab][tab]+ CHR(13) ;
[tab][tab][tab]+ lcLine3
[tab][tab]lnHeight = 43

[tab]CASE PCOUNT() = 6
[tab][tab]lcLine1 = [ ] ;
[tab][tab][tab]+ ALLTRIM(tcLine1) ;
[tab][tab][tab]+ [ ]
[tab][tab]lnLength = TXTWIDTH(lcLine1,[MS Sans Serif],9)

[tab][tab]lcLine2 = [ ] ;
[tab][tab][tab]+ ALLTRIM(tcLine2) ;
[tab][tab][tab]+ [ ]
[tab][tab]lnLine2 = TXTWIDTH(lcLine2,[MS Sans Serif],9)

[tab][tab]IF lnLine2 > lnLength
[tab][tab][tab]lnLength = lnLine2
[tab][tab]ENDI

[tab][tab]lcLine3 = [ ] ;
[tab][tab][tab]+ ALLTRIM(tcLine3) ;
[tab][tab][tab]+ [ ]
[tab][tab]lnLine3 = TXTWIDTH(lcLine3,[MS Sans Serif],9)

[tab][tab]IF lnLine3 > lnLength
[tab][tab][tab]lnLength = lnLine3
[tab][tab]ENDI

[tab][tab]lcLine4 = [ ] ;
[tab][tab][tab]+ ALLTRIM(tcLine4) ;
[tab][tab][tab]+ [ ]
[tab][tab]lnLine4 = TXTWIDTH(lcLine4,[MS Sans Serif],9)

[tab][tab]IF lnLine4 > lnLength
[tab][tab][tab]lnLength = lnLine4
[tab][tab]ENDI

[tab][tab]lcCaption = lcLine1 ;
[tab][tab][tab]+ CHR(13) ;
[tab][tab][tab]+ lcLine2 ;
[tab][tab][tab]+ CHR(13) ;
[tab][tab][tab]+ lcLine3 ;
[tab][tab][tab]+ CHR(13) ;
[tab][tab][tab]+ lcLine4
[tab][tab]lnHeight = 57
[tab]ENDC

[tab]lnWidth = (lnLength * lnSize) + 2

[tab]IF tnLeft + lnWidth > .Width - 5
[tab][tab]tnLeft = .Width - 5 - lnWidth [/color][color green]&& Ensure text remains within the form[/color][color blue]
[tab]ENDIF

[tab]WITH .lblToolTipText
[tab][tab].AutoSize = .F.
[tab][tab].BackColor = RGB(255,255,215)
[tab][tab].BorderStyle = 1
[tab][tab].Caption = lcCaption
[tab][tab].FontName = [MS Sans Serif]
[tab][tab].FontSize = 9
[tab][tab].Height = lnHeight
[tab][tab].Left = tnLeft
[tab][tab].Top = tnTop
[tab][tab].Width = lnWidth
[tab][tab].Visible = .T.
[tab]ENDWITH
ENDWITH[/color]

Have fun

ChrisRChamberlain
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top