Jump to content
Sign in to follow this  
matwachich

ListBox - ToolTip for long items

Recommended Posts

matwachich

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
Malkey

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
matwachich

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
Malkey

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
AZJIO

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
TrickyDeath

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
Melba23

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  

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      Hi dear
      I have a request
      I want a simplified example of how to create the toolbar
      With an example of pressing the buttons inside this bar
      for example
      Toolbar contains Three buttons
      open, save, And delete
      and i want  If i press a button from among these buttons a MSGBox appears
      I know this is easy
      But I did not know how to do it
      I hope you help me
      I apologize for the inconvenience
      Thank you in advance
    • kneze
      By kneze
      Hi
      first step i write ipconfig output to ipconfig.txt. Now i try to find all Adapters and get for each adapter: Adapter Name, Description, Media State and Mac Adress and put it to listbox. I search for "Ethernet Adapter" but they are other entrys like Wireless Adapter .. How can i get all Adapters from ipconfig.txt and information for each adapter Adapter Name, Description, Media State and Mac Adress and write to listbox ? 
      Would appreciate any help!
      #include <File.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 451, 328, 856, 237) $Button1 = GUICtrlCreateButton("Button1", 8, 8, 75, 25) $List1 = GUICtrlCreateList("", 88, 8, 353, 305) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select ;Case $GUI_EVENT_CLOSE Case $msg = $GUI_EVENT_CLOSE Exitloop Case $msg = $Button1 $FilePath= "C:\temp\IPconfig.txt" $StringToSearch= "Ethernet adapter" $CaseSense=0 $Lines=_FileCountLines($FilePath) $hFile=FileOpen($FilePath,0) $Lines=_FileCountLines($FilePath) For $i=0 To Number($Lines) $Test=FileReadLine($hFile,$i) If StringInStr($Test,$StringToSearch,$CaseSense) Then $filereadAdapter = FileReadLine($hFile,$i) $filereadDescription = FileReadLine($hFile,$i+4) $filereadMediaState = FileReadLine($hFile,$i+2) $filereadMAcAdress = FileReadLine($hFile,$i+5) GUICtrlSetData($List1 , "Adapter: " & $filereadAdapter & @CRLF& "Description: "& $filereadDescription & @CRLF & "Media State: " & $filereadMediaState & @CRLF & "Mac Adress: " & $filereadMAcAdress& @CRLF) ;ExitLoop EndIf Next FileClose($hFile)  
       
    • nacerbaaziz
      By nacerbaaziz
      Hello
      I have an inquiry please
      when i use the control get focus
      it don't detect the menu item
      there are any Method to do that?
      i'll use that to make a custom screen reader in my program
      please help me to do that
      I am waiting for your answers
      greetings to you
      Thank you in advance
       
    • 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 - 4.5 (on this version Microsoft destroy old rules) 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
×