Jump to content

Tooltip with $TIP_CENTER + $TIP_FORCEVISIBLE


TimRude
 Share

Recommended Posts

I'm seeing odd positioning behavior with the ToolTip command when using the $TIP_FORCEVISIBLE flag.

Here's sample code to create a GUI which, when right-clicked, will display a balloon tooltip for 2.5 seconds in the center of the GUI.

#NoTrayIcon
#include <APIConstants.au3>

Example()

Func Example()
    Local $hGUI = GUICreate("Sample GUI", 400, 300)
    Local $idText = GUICtrlCreateLabel("Right-click window to see tooltip", 20, 125, 360, Default, $SS_CENTER)
    GUICtrlSetFont(-1, 12)
    GUISetState(@SW_SHOW)

    Local $hTimer = 0
    While 1
        Local $iMsg = GUIGetMsg()
        Switch $iMsg
            Case $GUI_EVENT_CLOSE ; ESC pressed - close the dialog
                ExitLoop
            Case $GUI_EVENT_SECONDARYUP ; right-click on dialog to display tooltip
                Local $aPos = WinGetPos($hGUI)
                Local $iX = $aPos[0] + ($aPos[2] / 2)
                Local $iY = $aPos[1] + ($aPos[3] / 2)
                ToolTip("Here's your tooltip!", $iX, $iY, Default, Default, $TIP_BALLOON + $TIP_CENTER + $TIP_FORCEVISIBLE)
                $hTimer = TimerInit() ; start the clock running on the tooltip
        EndSwitch
        If $hTimer <> 0 Then
            If TimerDiff($hTimer) >= 2500 Then
                ; 2.5 seconds have elapsed, hide the tooltip
                ToolTip("")
                $hTimer = 0
            EndIf
        EndIf
    WEnd
    If $hTimer <> 0 Then ToolTip("")
    GUIDelete($hGUI)
EndFunc   ;==>Example

image.thumb.png.7152c6910ab8dece0f32870471f5b6e5.png

Now move the GUI over to the right so most of it is off the edge of the screen and then right-click it again to display the tooltip. I would expect the tooltip to be displayed as close to the right edge of the screen as possible without going off of it. However, there's a gap of about 60 pixels or so between the tooltip and the right-edge.

image.thumb.png.8f4a6cd179a68c6fa42df9d00447e08b.png

Now move the GUI over to the left so most of it is off the edge of the screen and then right-click it again to display the tooltip. I would expect the tooltip to be fully displayed as close to the left edge of the screen as possible without going off of it. However, the tooltip is allowed to be displayed partially off-screen.

image.thumb.png.13a28a1e6ce9fb1d689852b16be6ac03.png

In the ToolTip help docs, it says: "$TIP_FORCEVISIBLE (4) = Force the tooltip to always be visible confining it to monitor borders if necessary." It doesn't appear to be doing this quite right.

If I remove the $TIP_CENTER flag, it then positions the tooltip properly up against each edge of the screen. So there's evidently something about the combination of $TIP_CENTER and $TIP_FORCEVISIBLE that's throwing off the positioning calculations

Edited by TimRude
Link to comment
Share on other sites

A bit of additional testing finds that the gap on the right side is 1/2 the width of the tooltip. If I make the tooltip text longer, the gap becomes longer. And likewise the portion of the tooltip that displays off the left side of the screen is always no more than the left-half of the tooltip.

Link to comment
Share on other sites

  • TimRude changed the title to Tooltip with $TIP_CENTER + $TIP_FORCEVISIBLE

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...