Function Reference


GUICtrlSetBkColor

Sets the background color of a control.

GUICtrlSetBkColor ( controlID, backgroundcolor )

Parameters

controlID The control identifier (controlID) as returned by a GUICtrlCreate...() function, or -1 for the last created control.
backgroundcolor The RGB color to use.

Return Value

Success: 1.
Failure: 0.

Remarks

Only Button, Label, Checkbox, Group, Radio, Edit, Input, List, Listview, ListviewItem, Treeview, TreeviewItem, Graphic, Progress, Slider and Combo controls can currently be colored.

Progress controls cannot be painted if the "Windows XP style" is used.
Checkbox, Radio, Group Progress, Combo controls cannot be painted if the "Windows XP/Vista style" is used.

Button controls are always painted in "Windows Classic style". They cannot have the $BS_ICON style.

The special flag $GUI_BKCOLOR_TRANSPARENT can be used with Label, Group, Radio, Checkbox controls to give them a transparent background.

The special flag $GUI_BKCOLOR_LV_ALTERNATE can be used with Listview control to give alternate background of the ListviewItems lines.
The odd lines will get the color set by GUICtrlSetBkColor() of the Listview control.
The even lines will get the color set by GUICtrlSetBkColor() of the ListviewItem control.

Related

GUICtrlCreate..., GUICtrlSetColor, GUICtrlSetDefBkColor

Example

Example 1

#include <ColorConstants.au3>
#include <GUIConstantsEx.au3>

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example", 300, 200)

    ; Create a label control.
    Local $idLabel = GUICtrlCreateLabel("A string of text", 10, 10, 185, 17)
    Local $idButton_Close = GUICtrlCreateButton("Close", 210, 170, 85, 25)

    ; Set the background color of the label control.
    GUICtrlSetBkColor($idLabel, $COLOR_RED)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idButton_Close
                ExitLoop

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

Example 2

#include <ColorConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>

Example()

Func Example()
    ; Create a GUI with a listview.
    Local $hGUI = GUICreate("Colored ListView Items", 250, 170, 100, 200, -1)
    Local $idListview = GUICtrlCreateListView("col1|col2|col3", 10, 10, 230, 150)

    ; Alternate between the listview background color and the listview item background color.
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE)

    ; Set the background color for the listview.
    ; Odd listview items will be shown with the background color of the listview,
    ; even with the background color of the listview item.
    GUICtrlSetBkColor(-1, $COLOR_AQUA)

    ; Create listview items and set the backgroundcolor for each of them.
    GUICtrlCreateListViewItem("item1|col12|col13", $idListview)

    ; The following line could be dropped as the background color is taken from the listview.
    GUICtrlSetBkColor(-1, $COLOR_GREEN)
    GUICtrlCreateListViewItem("item2|col22|col23", $idListview)
    GUICtrlSetBkColor(-1, $COLOR_GREEN)
    GUICtrlCreateListViewItem("item3|col32|col33", $idListview)

    ; The following line could be dropped as the background color is taken from the listview.
    GUICtrlSetBkColor(-1, $COLOR_GREEN)

    ; Change the color of a single listview item.
    GUICtrlCreateListViewItem("Now|change|color", $idListview)
    GUICtrlSetBkColor(-1, $COLOR_LIME)
    GUICtrlCreateListViewItem("item5|col52|col53", $idListview)

    ; The following line could be dropped as the background color is taken from the listview.
    GUICtrlSetBkColor(-1, $COLOR_GREEN)
    GUICtrlCreateListViewItem("item6|col62|col63", $idListview)
    GUICtrlSetBkColor(-1, $COLOR_GREEN)
    GUISetState(@SW_SHOW, $hGUI)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls
    GUIDelete($hGUI)
EndFunc   ;==>Example