Sign in to follow this  
Followers 0
matwachich

ListBox - ToolTip for long items

9 posts in this topic

Hello guys!

I've got a simple question:

- Is it possible to display a ToolTip on ListBox Item?

- I want to display it when an Item is too long for the ListBox width, and a part of it is hidden (Just like a ListView does, but for a ListBox)

Thanks!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Thanks for the answer.

But it's not really what i'm looking for.

I want the toolTips to display when i hover the long item, because the clique event is already used.

Thanks

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thank you so much Malkey! ;)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Thanks!

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0

  • Similar Content

    • Ascer
      By Ascer
      1. Description.
      Udf working with MSDN System.Collections.ArrayList. Allow you to make fast operations on huge arrays, speed is even x10 better than basic _ArrayAdd.  Not prefered for small arrays < 600 items. 2. Requirements
      .NET Framework 1.1+ System Windows 3. Possibilities.
      ;=============================================================================================================== ; UDF Name: List.au3 ; ; Date: 2018-02-17, 10:52 ; Description: Simple udf to create System Collections as ArrayList and make multiple actions on them. ; ; Function(s): _ListCreate -> Creates a new list ; _ListCapacity -> Gets a list size in bytes ; _ListCount -> Gets items count in list ; _ListIsFixedSize -> Get bool if list if fixed size ; _ListIsReadOnly -> Get bool if list is read only ; _ListIsSynchronized -> Get bool if list is synchronized ; _ListGetItem -> Get item on index ; _ListSetItem -> Set item on index ; ; _ListAdd -> Add item at end of list ; _ListClear -> Remove all list items ; _ListClone -> Duplicate list in new var ; _ListContains -> Get bool if item is in list ; _ListGetHashCode -> Get hash code for list ; _ListGetRange -> Get list with items between indexs ; _ListIndexOf -> Get index of item ; _ListInsert -> Insert a new item on index ; _ListInsertRange -> Insert list into list on index ; _ListLastIndexOf -> Get index last of item ; _ListRemove -> Remove first found item ; _ListRemoveAt -> Remove item in index ; _ListRemoveRange -> Remove items between indexs ; _ListReverse -> Reverse all items in list ; _ListSetRange -> Set new value for items in range ; _ListSort -> Sort items in list (speed of reading) ; _ListToString -> Get list object name ; _ListTrimToSize -> Remove unused space in list ; ; Author(s): Ascer ;=============================================================================================================== 4. Downloads
      List.au3 5. Examples
      SpeedTest _ArrayAdd vs ListAdd SpeedTest ArraySearch vs ListIndexOf Basic usage - crating guild with members  
    • nacerbaaziz
      By nacerbaaziz
      can we  create a list box with  Columns?
      welcome everybody
      Dears I have a question if you let me
      can we  create a list box with  Columns?
      i know we can create a list view with Columns
      but my question is about the list box
      I'm waiting your responses
      Thank you in advance
    • nacerbaaziz
      By nacerbaaziz
      Detect if the focus item is a button or check box
      Hello everyone.
      My dears I have a problem
      When I try to use
      ControlGetFocus function
      it  doesn't recognize the check  boxes.
      The result is that the selector is a button
      Although the specified is a check box
      but I want a way to identify the check boxes.
      Because I want to make a tool that helps screen readers users
      I hope you have the solution.
      Thank you in advance.