Jump to content

ListBox - ToolTip for long items


matwachich
 Share

Recommended Posts

Here is an attempt at having tool tips on the long list box items.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Example()


Func Example()
    Local $MESSAGE = "The following buttons have been clicked.|line 3."
    Local $add, $clear, $mylist, $close, $msg, $tt = 0
    Local $iListBoxWidth = 23 ; Number of characters that will fit in lost box width.
    Static $iNum = 1
    Local $hGui = GUICreate("My GUI list") ; will create a dialog box that when displayed is centered

    $add = GUICtrlCreateButton("Add", 64, 32, 75, 25)
    $clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25)
    $mylist = GUICtrlCreateList("buttons that have been clicked", 176, 32, 143, 97, BitOR($WS_BORDER, $WS_VSCROLL))
    GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling
    GUICtrlSetData(-1, $MESSAGE)
    $close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25)

    GUISetState()

    $msg = 0
    While $msg <> -3 ; $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()
        $aCI = GUIGetCursorInfo($hGui)
        If $tt = 1 And $aCI[4] <> $mylist Then
            $tt = 0
            ToolTip("")
        EndIf
        Select
            Case $msg = $add
                GUICtrlSetData($mylist, "Add button clicked No" & $iNum)
                $iNum += 1
            Case $msg = $clear
                GUICtrlSetData($mylist, "")
            Case $msg = $close
                MsgBox(0, "", "the closing button has been clicked", 2)
                Exit
            Case $msg = $mylist
                If StringLen(GUICtrlRead($mylist)) > $iListBoxWidth Then
                    ToolTip(GUICtrlRead($mylist))
                    $tt = 1
                Else
                    ToolTip("")
                    $tt = 0
                EndIf
        EndSelect
    WEnd
EndFunc   ;==>Example
Link to comment
Share on other sites

Here is an example at having a tool tip appear when hovering over a long, list box item.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListBox.au3>
#include <GUIConstantsEx.au3>

Example()


Func Example()
    Local $MESSAGE = "The following buttons have been clicked.|line 3."
    Local $add, $clear, $mylist, $close, $msg

    ; --- Variables for Tool Tip Hover ---
    Local $aCI, $iIndex, $sText, $tt = 0
    Local $iListBoxWidth = 23 ; Number of characters that will fit in lost box width.
    ; -------------------------------------

    Local $iNum = 1
    Local $hGui = GUICreate("My GUI list") ; will create a dialog box that when displayed is centered

    $add = GUICtrlCreateButton("Add", 64, 32, 75, 25)
    $clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25)
    $mylist = GUICtrlCreateList("buttons that have been clicked", 176, 32, 143, 97, BitOR($WS_BORDER, $WS_VSCROLL))
    GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling
    GUICtrlSetData(-1, $MESSAGE)
    $close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25)

    GUISetState()

    $msg = 0
    While $msg <> -3 ; $GUI_EVENT_CLOSE

        ;--- Tool Tip when hover over list box item with greater than '$iListBoxWidth' characters ---
        $aCI = GUIGetCursorInfo($hGui)
        If $aCI[4] = $mylist Then
            $iIndex = _GUICtrlListBox_ItemFromPoint($mylist, $aCI[0] - 176, $aCI[1] - 32)
            $sText = _GUICtrlListBox_GetText($mylist, $iIndex)
            If StringLen($sText) > $iListBoxWidth Then
                ToolTip($sText)
                $tt = 1
            Else
                ToolTip("")
                $tt = 0
            EndIf
        EndIf
        If $tt = 1 And $aCI[4] <> $mylist Then
            $tt = 0
            ToolTip("")
        EndIf
        ; -------- End of Tool Tip Hover ---------------

        $msg = GUIGetMsg()
        Select
            Case $msg = $add
                GUICtrlSetData($mylist, "Add button clicked No" & $iNum)
                $iNum += 1
            Case $msg = $clear
                GUICtrlSetData($mylist, "")
            Case $msg = $close
                MsgBox(0, "", "the closing button has been clicked", 2)
                Exit
        EndSelect
    WEnd
EndFunc   ;==>Example
Link to comment
Share on other sites

  • 3 weeks later...

Tip in item position

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListBox.au3>

Example()

Func Example()
    Local $MESSAGE = "The following buttons have been clicked.|line 3."
    Local $add, $clear, $mylist, $close, $msg, $aRect, $tRect, $iTmpMouseY, $hListBox

    ; --- Variables for Tool Tip Hover ---
    Local $aCI, $iIndex, $sText, $tt = 0
    Local $iListBoxWidth = 23 ; Number of characters that will fit in lost box width.
    ; -------------------------------------

    Local $iNum = 1
    Local $hGui = GUICreate("My GUI list") ; will create a dialog box that when displayed is centered

    $add = GUICtrlCreateButton("Add", 64, 32, 75, 25)
    $clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25)
    $mylist = GUICtrlCreateList("buttons that have been clicked", 176, 32, 143, 97, BitOR($WS_BORDER, $WS_VSCROLL))
    GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling
    GUICtrlSetData(-1, $MESSAGE)
    $hListBox = GUICtrlGetHandle(-1)
    $close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25)

    GUISetState()

    While 1

        ;--- Tool Tip when hover over list box item with greater than '$iListBoxWidth' characters ---
        $aCI = GUIGetCursorInfo($hGui)
        If $aCI[4] = $mylist And $iTmpMouseY <> $aCI[1] Then
            $iTmpMouseY = $aCI[1]
            $iIndex = _GUICtrlListBox_ItemFromPoint($hListBox, $aCI[0] - 176, $aCI[1] - 32)
            $sText = _GUICtrlListBox_GetText($hListBox, $iIndex)
            If StringLen($sText) > $iListBoxWidth Then
                $aRect = _GUICtrlListBox_GetItemRect($hListBox, $iIndex)
                $tRect = _WinAPI_GetWindowRect($hListBox)
                ToolTip($sText, $aRect[0] + DllStructGetData($tRect, "Left"), $aRect[3] + 3 + DllStructGetData($tRect, "Top"))
                $tt = 1
            Else
                ToolTip("")
                $tt = 0
            EndIf
        EndIf
        If $tt = 1 And $aCI[4] <> $mylist Then
            $tt = 0
            ToolTip("")
        EndIf
        ; -------- End of Tool Tip Hover ---------------

        $msg = GUIGetMsg()
        Switch $msg
            Case $add
                GUICtrlSetData($mylist, "121221367456 Add button clicked No" & $iNum)
            Case $clear
                GUICtrlSetData($mylist, "")
            Case $close
                MsgBox(0, "", "the closing button has been clicked", 2)
                Exit
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>Example
Edited by AZJIO
Link to comment
Share on other sites

  • 1 year later...

First of all sorry for "necro" post!

I just do not wanted to make a new topic with nearly same question, what was solved here.

My question is the same as the original topic maker, but with TreeView. Does it posible to put a tooltip on all TreeView item? (like a short description on them) or better to make a little memo next to the TreeView and write there the description for the selected element?

Sry for my bad English, and double sry, but I am learning AutoIT language by myself. :)

[u]Tricky[/u]

You can't teach a man anything, you can only help him, find it within himself. (Galileo Galilei)

Link to comment
Share on other sites

  • Moderators

TrickyDeath,

 

My question is the same as the original topic

No it is not - it is about a completely different control. So please start a new thread and do not hijack this one. :naughty:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...