Sign in to follow this  
Followers 0
FinalVersion

Change Font Color Etc Of ListBox

10 posts in this topic




#2 ·  Posted (edited)

Do GuiCtrlSetColor on each ListViewItem as you create them.

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
    
GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
GUISetBkColor(0x00E0FFFF)  ; will change background color

$listview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150);,$LVS_SORTDESCENDING)
$item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview)
$item2 = GUICtrlCreateListViewItem("............item1|col12|col13", $listview)
GUICtrlSetColor (-1, 0x0000FF)
$item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview)
GUICtrlSetColor (-1, 0xFF0000)
GUISetState()

Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE
Edited by exodius

Share this post


Link to post
Share on other sites

Do GuiCtrlSetColor on each ListViewItem as you create them.

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
    
GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
GUISetBkColor(0x00E0FFFF)  ; will change background color

$listview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150);,$LVS_SORTDESCENDING)
$item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview)
$item2 = GUICtrlCreateListViewItem("............item1|col12|col13", $listview)
GUICtrlSetColor (-1, 0x0000FF)
$item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview)
GUICtrlSetColor (-1, 0xFF0000)
GUISetState()

Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE
You use ListView.

Share this post


Link to post
Share on other sites

Totally overlooked that he said ListBox, although the principal is the exact same.

Here's how to do it with a Listbox:

#include <GUIConstants.au3>
    
GUICreate("My GUI list") ; will create a dialog box that when displayed is centered

$mylist = GUICtrlCreateList("buttons that have been clicked", 176, 32, 121, 97)
GUICtrlSetColor (-1, 0xFF0000)
GUICtrlSetData (-1, "Test1")
GUICtrlSetData (-1, "Test2")
GUICtrlSetData (-1, "Test3")
GUICtrlSetData (-1, "Test4")
GUICtrlSetData (-1, "Test5")
GUISetState()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
WEnd

Share this post


Link to post
Share on other sites

Totally overlooked that he said ListBox, although the principal is the exact same.

Here's how to do it with a Listbox:

#include <GUIConstants.au3>
    
GUICreate("My GUI list") ; will create a dialog box that when displayed is centered

$mylist = GUICtrlCreateList("buttons that have been clicked", 176, 32, 121, 97)
GUICtrlSetColor (-1, 0xFF0000)
GUICtrlSetData (-1, "Test1")
GUICtrlSetData (-1, "Test2")
GUICtrlSetData (-1, "Test3")
GUICtrlSetData (-1, "Test4")
GUICtrlSetData (-1, "Test5")
GUISetState()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
WEnd
Thank you.

Share this post


Link to post
Share on other sites

Do GuiCtrlSetColor on each ListViewItem as you create them.

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
    
GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
GUISetBkColor(0x00E0FFFF)  ; will change background color

$listview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150);,$LVS_SORTDESCENDING)
$item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview)
$item2 = GUICtrlCreateListViewItem("............item1|col12|col13", $listview)
GUICtrlSetColor (-1, 0x0000FF)
$item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview)
GUICtrlSetColor (-1, 0xFF0000)
GUISetState()

Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE

Ok I'm a newbie when it comes to AutoIT and am struggling with this one. I've got the concept of setting the text color when you are adding each individual item in the manner you outline above; however, the problem I'm running into is I'm adding my listview items via the _GUICtrlListView_AddArray function so I can't figure out how to change the color of the text for each array when I add them. Is there a way to do this?

Thanks.

Share this post


Link to post
Share on other sites

Ahhhhh.... can someone answer the question? about changing the font and Color of a LISTBOX? NOT a 'ListView' and not NOT a 'List' please...

A LISTBOX!!:) For some reason GUICtrlSetFont and GUICtrlSetColor doesn't work for a LISTBOX.... It does work fine for listview and list controls.

Share this post


Link to post
Share on other sites

Why would you resurrect a 3+ year old thread? GUICtrlsetColor works just fine for a list box, but it will recolor all the contents of the listbox, not just one line at a time.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Why would you resurrect a 3+ year old thread? GUICtrlsetColor works just fine for a list box, but it will recolor all the contents of the listbox, not just one line at a time.

Sorry BrewMan I didn't mean to come across as and ass. I had made a stupid mistake in my code and came here looking for answers. I posted on this thread because the question was very specific to a "list box" and was not answered specifically about a list box but referred to other controls.

These forum is my bible for Autoit when the manual(which is excellent BTW) doesn't answer my question. As long as I'm actually posting I should thank a few hundred of the folks that have answered questions on this forum and helped me out over the years.. THANKS VERY MUCH!

Why did I post on a 3 year old thread? Because 3 year old threads and some much older have helped me greatly over the years and when I do a search I want as few threads to read through as possible. Because it is old doesn’t mean it can’t help. We really don't need another thread, for poor slobs like me to read.. Just need this one answered correctly and specific to both changing the font and changing the text color of a list box. So Allow me to contribute… Examples of working code when your trying to figure out a problem are invaluable.

#include
#include
#include

$Debug_LB = False ; Check ClassName being passed to ListBox functions, set to True and use a handle to another control to see it work

_Main()

Func _Main()
Local $hListBox

; Create GUI
GUICreate("List Box Begin Update", 400, 296)
$hListBox = GUICtrlCreateList("", 2, 2, 396, 296)
GUICtrlSetColor (-1, 0xFF0000)
GUICtrlSetFont(-1,15,500)
GUISetState()

; Add files
_GUICtrlListBox_BeginUpdate($hListBox)
_GUICtrlListBox_ResetContent($hListBox)
_GUICtrlListBox_InitStorage($hListBox, 100, 4096)
_GUICtrlListBox_Dir($hListBox, @WindowsDir & "\win*.exe")
_GUICtrlListBox_AddFile($hListBox, @WindowsDir & "\notepad.exe")
_GUICtrlListBox_Dir($hListBox, "", $DDL_DRIVES)
_GUICtrlListBox_Dir($hListBox, "", $DDL_DRIVES, False)
_GUICtrlListBox_EndUpdate($hListBox)

; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>_Main
Edited by Viper2025

Share this post


Link to post
Share on other sites

Still not seeing your problem, that code works just fine, the text is red, and the font size is 15 point.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
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
Sign in to follow this  
Followers 0