Jump to content

change color of only one line of a list


bobbintb
 Share

Recommended Posts

i have a list control:

$List1 = GUICtrlCreateList($array, 8, 8, 505, 409, BitAND($LBS_DISABLENOSCROLL, $LBS_NOINTEGRALHEIGHT, $LBS_NOSEL, $LBS_NOTIFY, $LBS_STANDARD, $LBS_USETABSTOPS))

i add items to the list though a redim and fileselectfolder command. the problem i am having is there is a point in my script where it goes through the items in the list and i want to change the color of the text as it processes. for example, the script processes the first item in the list. if that went well is changes the text green, or maybe even adds "success" the the end. it keeps doing this until all items are processed. i know how to change the color but i cant figure how to change it line by line.

Link to comment
Share on other sites

i have a list control:

$List1 = GUICtrlCreateList($array, 8, 8, 505, 409, BitAND($LBS_DISABLENOSCROLL, $LBS_NOINTEGRALHEIGHT, $LBS_NOSEL, $LBS_NOTIFY, $LBS_STANDARD, $LBS_USETABSTOPS))

i add items to the list though a redim and fileselectfolder command. the problem i am having is there is a point in my script where it goes through the items in the list and i want to change the color of the text as it processes. for example, the script processes the first item in the list. if that went well is changes the text green, or maybe even adds "success" the the end. it keeps doing this until all items are processed. i know how to change the color but i cant figure how to change it line by line.

Search for $ODA_DRAWENTIRE.

Looks like your version of AutoIt is a bit old though.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Search for $ODA_DRAWENTIRE.

Looks like your version of AutoIt is a bit old though.

thanks, i think that got me in the right direction. why do you say my autoit is a bit old? i have the latest. im probably just doing something in a roundabout way.

Link to comment
Share on other sites

i still cant seem to it. heres what i have:

If @error = 0 Then
            _GUICtrlListBox_ReplaceString($List1, $i - 1, "SUCCESS! - " & $array[$i - 1][0])
            GUICtrlSetColor($List1, 0x49E20E)

        Else
            _GUICtrlListBox_ReplaceString($List1, $i - 1, " Failed: Error - " & $array[$i - 1][0])
            GUICtrlSetColor($List1, 0xff0000)
        EndIf

i got it to change the line. but the change GUICtrlSetColor changes the entire control when i only want that line changed.

Link to comment
Share on other sites

  • Moderators

bobbintb,

Perhaps if you create your own "simulated list" using labels? Along these lines:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Global $aLabels[20], $aData[20]

; Fill data array
For $i = 0 To 19
    $aData[$i] = $i & " - " & $i & " - " & $i & " - " & $i
Next

; Create GUI
$hGui = GUICreate("Colour Line List", 420, 420)

; Create "list"
GUICtrlCreateGraphic(8, 8, 404, 404, $SS_BLACKFRAME)
For $i = 0 To 19
    $aLabels[$i] = GUICtrlCreateLabel($aData[$i], 10, 10 + ($i * 20), 400, 20)
Next

GUISetState()

While 1
    For $i = 0 To 19
        ; Wait 1 Sec
        $iBegin = TimerInit()
        Do
            Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                    Exit
            EndSwitch
        Until TimerDiff($iBegin) > 1000
        ; Change line colour
        GUICtrlSetColor($aLabels[$i], 0xFF0000)
    Next
WEnd

If you need more lines that can fit on your GUI it gets a bit more complicated, but still doable. You would need functions to move the data between the labels and insert the new data at the top or bottom, and to keep track of the colours. Let me know if you need that and I will take a look at how it might be done. :mellow:

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

  • Moderators

bobbintb,

That was fun! :( I changed tack and went for a complete redraw each time rather than shuffling the labels. It does not seem to have affected the result - the list flickers a bit when you drag the scrollbar thumb, but that will always cause problems regardless of the method as all the labels have to be redrawn one way or another.

Click on a line to change its colour - simulating your code doing so as the line is processed - and it stays that colour as you scroll.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiScrollBars.au3>
#include <ScrollBarConstants.au3>

Global $iItems = 50, $iNumLabels = 20 ; Items = number in list, NumLabels = number of labels in GUI
Global $iScrollPos = 0, $iCurrScrollPos = 0, $iCurrentTopIndex = 0
Global $aLabelData[$iNumLabels], $aData[$iItems][2]

; Fill data array
For $i = 0 To UBound($aData) - 1
    $aData[$i][0] = $i & " - " & $i & " - " & $i & " - " & $i ; Data
    $aData[$i][1] = 0                                         ; State
Next

; Create GUI
$hGui = GUICreate("Scroll Colour Line List", 420, 20 + $iNumLabels * 20)

; Create "list"
GUICtrlCreateGraphic(8, 8, 384, 4 + ($iNumLabels * 20), $SS_BLACKFRAME)
For $i = 0 To $iNumLabels - 1
    $aLabelData[$i] = GUICtrlCreateLabel($aData[$i][0], 10, 10 + ($i * 20), 380, 20)
Next

GUISetState()

; Create Scrollbar
$hScroller = GUICreate("", 17, $iNumLabels * 20, 400, 10, $WS_CHILD, -1, $hGUI)
GUISetState()

; Set scroll bar to run from 1 to 100
_GUIScrollBars_Init($hScroller)
_GUIScrollBars_ShowScrollBar($hScroller, $SB_HORZ , False)
_GUIScrollBars_SetScrollInfoPos($hScroller, $SB_VERT, 100)
_GUIScrollBars_SetScrollRange($hScroller, $SB_VERT, 0, (200 - _GUIScrollBars_GetScrollInfoPos($hScroller, $SB_VERT)))
_GUIScrollBars_SetScrollInfoPos($hScroller, $SB_VERT, 0)

GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")

While 1

    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        ; Simulate the line colour changing
        Case $aLabelData[0] To $aLabelData[19]
            $iIndex = $iMsg - $aLabelData[0]
            ; Change line colour
            GUICtrlSetColor($aLabelData[$iIndex], 0xFF0000)
            ; Change data array state
            $aData[$iCurrentTopIndex + $iIndex][1] = 1
    EndSwitch

    ConsoleWrite($iScrollPos & @CRLF)

WEnd

; This function comes directly from the _GUIScrollBars_Init example - except the <<<<<<<<<<<< lines

Func WM_VSCROLL($hWnd, $Msg, $wParam, $lParam)
    #forceref $Msg, $wParam, $lParam
    Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
    Local $index = -1, $yChar, $yPos
    Local $Min, $Max, $Page, $Pos, $TrackPos

    For $x = 0 To UBound($aSB_WindowInfo) - 1
        If $aSB_WindowInfo[$x][0] = $hWnd Then
            $index = $x
            $yChar = $aSB_WindowInfo[$index][3]
            ExitLoop
        EndIf
    Next
    If $index = -1 Then Return 0

    ; Get all the vertial scroll bar information
    Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
    $Min = DllStructGetData($tSCROLLINFO, "nMin")
    $Max = DllStructGetData($tSCROLLINFO, "nMax")
    $Page = DllStructGetData($tSCROLLINFO, "nPage")
    ; Save the position for comparison later on
    $yPos = DllStructGetData($tSCROLLINFO, "nPos")
    $Pos = $yPos
    $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")

    Switch $nScrollCode
        Case $SB_TOP ; user clicked the HOME keyboard key
            DllStructSetData($tSCROLLINFO, "nPos", $Min)
        Case $SB_BOTTOM ; user clicked the END keyboard key
            DllStructSetData($tSCROLLINFO, "nPos", $Max)
        Case $SB_LINEUP ; user clicked the top arrow
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - (100 / ($iItems - $iNumLabels))) ; I altered this line <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        Case $SB_LINEDOWN ; user clicked the bottom arrow
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + (100 / ($iItems - $iNumLabels))) ; I altered this line <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        Case $SB_PAGEUP ; user clicked the scroll bar shaft above the scroll box
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)
        Case $SB_PAGEDOWN ; user clicked the scroll bar shaft below the scroll box
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)
        Case $SB_THUMBTRACK ; user dragged the scroll box
            DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
    EndSwitch

;~    // Set the position and then retrieve it.  Due to adjustments
;~    //   by Windows it may not be the same as the value set.

    DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
    _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
    _GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
    ;// If the position has changed, scroll the window and update it
    $Pos = DllStructGetData($tSCROLLINFO, "nPos")

    If ($Pos <> $yPos) Then
        _GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos))
        $yPos = $Pos
        $iScrollPos = Round(($iItems - $iNumLabels) * $Pos / 100) ; I added from here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        If $iScrollPos <> $iCurrScrollPos Then
            $iIndex = $iCurrentTopIndex + $iScrollPos - $iCurrScrollPos
            For $i = 0 To $iNumLabels - 1
                ; Write the labels to match the required data
                GUICtrlSetData($aLabelData[$i], $aData[$iIndex + $i][0])
                GUICtrlSetColor($aLabelData[$i], 0x000000)
                ; Change the colour if the state requires
                If $aData[$iIndex + $i][1] = 1 Then GUICtrlSetColor($aLabelData[$i], 0xFF0000)
            Next
            $iCurrScrollPos = $iScrollPos
            $iCurrentTopIndex = $iIndex
        EndIf ; To here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    EndIf

    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_VSCROLL

I hope that solves your problem. Please let me know if it needs any alteration. :mellow:

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

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