Jump to content

LIST control background color?


September
 Share

Recommended Posts

Hi September
I hope you find someone being able to do it with a list control (e.g. GUICtrlCreateList)
Meanwhile, here is the easy way to do it with a listview control. Who knows, it may help you in case you want to try a "no header listview control with 1 column only" looking like a list control.

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

Example()

Func Example()
    Local $hGUI = GUICreate("Alternate color in LV", 270, 175, 100, 200)
    Local $idListview = GUICtrlCreateListView("", 10, 10, 250, 155, $LVS_NOCOLUMNHEADER)
    _GUICtrlListView_AddColumn($idListview, "", 228)

    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE) ; <============
    GUICtrlSetBkColor(-1, 0xFFFFFF) ; white background (will show on odd lines)

    For $i = 1 To 20
        GUICtrlCreateListViewItem("Line " & $i, $idListview)
        GUICtrlSetBkColor(-1, 0xE6E6E6) ; light grey background (will show only on even lines)
    Next

    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd

    GUIDelete($hGUI)
EndFunc   ;==>Example

Alternate-color-in-LV.png
Link to comment
Share on other sites

Maybe this ?

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

; ListBox OwnerDrawn Colors

Global Const $tagDRAWITEMSTRUCT = "uint CtlType;uint CtlID;uint itemID;uint itemAction;uint itemState;hwnd hwndItem;handle hDC;dword rcItem[4];ptr itemData"

Global Const $ODA_DRAWENTIRE = 1
Global Const $ROW_HEIGHT = 24, $MARGIN = 4

Example()

Func Example()
  GUICreate("Ownerdrawn Listbox", 300, 300)
  Local $idListBox = GUICtrlCreateList("", 4, 4, 292, 292, $WS_VSCROLL + $LBS_OWNERDRAWFIXED)
  _GUICtrlListBox_SetItemHeight($idListBox, $ROW_HEIGHT)

  For $i = 0 To 19
    _GUICtrlListBox_AddString($idListBox, "")
  Next

  GUIRegisterMsg($WM_DRAWITEM, WM_DRAWITEM)
  GUISetState()

  Do
  Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

Func WM_DRAWITEM($hWnd, $iMsg, $wParam, $lParam)
  Local $tDRAWITEMSTRUCT = DllStructCreate($tagDRAWITEMSTRUCT, $lParam)
  Switch $tDRAWITEMSTRUCT.itemAction
    Case $ODA_DRAWENTIRE
      Local $tRECT = DllStructCreate($tagRECT, DllStructGetPtr($tDRAWITEMSTRUCT, "rcItem"))
      Local $hBrush = _WinAPI_CreateSolidBrush(Mod($tDRAWITEMSTRUCT.itemID, 2) ? 0xFFFFFF : 0xE0E0E0)
      _WinAPI_FillRect($tDRAWITEMSTRUCT.hDC, $tRECT, $hBrush)

      Local $sItemText = "Line " & $tDRAWITEMSTRUCT.itemID
      $tRECT.Left += $MARGIN
      $tRECT.Top += $MARGIN
      _WinAPI_DrawText($tDRAWITEMSTRUCT.hDC, $sItemText, $tRECT, $DT_LEFT)
      _WinAPI_DeleteObject($hBrush)
  EndSwitch
  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DRAWITEM

 

Edited by Nine
increased conciseness
Link to comment
Share on other sites

  • 3 weeks later...

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