INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Tips -N- Tricks

How can I create ToolTipText with multiple lines? by ChrisRChamberlain
Posted: 5 Feb 03 (Edited 2 Jul 04)

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 .lblToolTipText

Change the following properties of the label

.FontName = [MS Sans Serif]
.FontSize = 9
.Visible = .F.

In the .MouseEnter() event of the control(s) for which you wish to display ToolTipText put :-

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)


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

In the .MouseLeave() event of the control(s) put :-

THISFORM.lblToolTipText.Visible = .F.


Remove any existing ToolTipText for the control(s).

Create a new form method called .mToolTipText() and put :-

LPARAMETERS ;    
    tnLeft ,;
    tnTop ,;
    tcLine1 ,;
    tcLine2 ,;
    tcLine3 ,;
    tcLine4

LOCAL lcCaption    ,;
    lcLine1 ,;
    lcLine2 ,;
    lcLine3 ,;    
    lcLine4 ,;
    lnHeight ,;
    lnSize ,;
    lnWidth

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

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

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

        IF lnLine2 > lnLength
            lnLength    = lnLine2
        ENDI    

        lcCaption = lcLine1 ;
            + CHR(13) ;
            + lcLine2
        lnHeight = 29
        
    CASE PCOUNT() = 5
        lcLine1 = [ ]    ;
            + ALLTRIM(tcLine1) ;
            + [ ]
        lnLength = TXTWIDTH(lcLine1,[MS Sans Serif],9)
    
        lcLine2 = [ ]    ;
            + ALLTRIM(tcLine2) ;
            + [ ]
        lnLine2 = TXTWIDTH(lcLine2,[MS Sans Serif],9)    

        IF lnLine2 > lnLength
            lnLength    = lnLine2
        ENDI    

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

        IF lnLine3 > lnLength
            lnLength    = lnLine3
        ENDI    

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

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

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

        IF lnLine2 > lnLength
            lnLength    = lnLine2
        ENDI    

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

        IF lnLine3 > lnLength
            lnLength    = lnLine3
        ENDI    

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

        IF lnLine4 > lnLength
            lnLength    = lnLine4
        ENDI    

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

    lnWidth = (lnLength * lnSize) + 2

    IF tnLeft + lnWidth > .Width - 5
        tnLeft = .Width - 5 - lnWidth
&& Ensure text remains within the form
    ENDIF
        
    WITH .lblToolTipText
        .AutoSize = .F.
        .BackColor = RGB(255,255,215)
        .BorderStyle = 1
        .Caption = lcCaption
        .FontName = [MS Sans Serif]
        .FontSize = 9
        .Height = lnHeight
        .Left    = tnLeft
        .Top = tnTop
        .Width = lnWidth
        .Visible = .T.
    ENDWITH
ENDWITH


Have fun

ChrisRChamberlain

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close