Bert Posted January 23, 2006 Share Posted January 23, 2006 (edited) Is it possible to have a GUICtrlCreateList with each line listed as a different color? I took a helpfile code to show what I'm looking for. It doesn't change the color the way I want, but you will get the idea of what I'm trying to do. I want it so when I click on the "Add Red" button, the text that is put into the GUICtrlCreateList window will be red for that line, while all the other text will be black. If I click "Add Black", the text that is put into the GUICtrlCreateList window will be black for that line. It is important for any text already in GUICtrlCreateList to remain the color it is when it was first entered. Is this possible? #include <GUIConstants.au3> GLOBAL $MESSAGE = "This text will stay black" GUICreate("My GUI list"); will create a dialog box that when displayed is centered $add=GUICtrlCreateButton ("Add Red", 64,32,75,25) $button = GUICtrlCreateButton ("Add Black", 64,68,75,25) $clear=GUICtrlCreateButton ("Clear", 64,102,75,25) $mylist=GUICtrlCreateList ("black black, black", 176,32,210,97) GUICtrlSetLimit(-1,200); to limit horizontal scrolling GUICtrlSetData(-1,$MESSAGE) $close=GUICtrlCreateButton ("my closing button", 64,160,175,25) GUISetState () $msg = 0 ;$color2 = GUICtrlSetColor($text1,0x000000) While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select case $msg = $add $text1 = GUICtrlSetData($mylist,"This text needs to be red|") $color1 = GUICtrlSetColor($text1,0xFF0000); doesn't work case $msg = $clear GUICtrlSetData($mylist,"") case $msg = $button $text1 = GUICtrlSetData($mylist,"This text needs to be black|") Case $msg = $close MsgBox(0,"", "the closing button has been clicked",2) Exit EndSelect Wend Edited January 23, 2006 by vollyman The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
GaryFrost Posted January 23, 2006 Share Posted January 23, 2006 (edited) From help file for GuiCtrlSetColorRemarks Only Label, Checkox, Group, Radio, Edit, Input, Listview, Treeview, Graphic and Progress controls can currently be colored. Edited January 23, 2006 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Danny35d Posted January 23, 2006 Share Posted January 23, 2006 From help file for GuiCtrlSetColorRemarks Only Label, Checkox, Group, Radio, Edit, Input, Listview, Treeview, Graphic and Progress controls can currently be colored.This is true but, only apply to Listview control and not to List control.... AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line Link to comment Share on other sites More sharing options...
Bert Posted January 23, 2006 Author Share Posted January 23, 2006 (edited) Has anyone got a idea for a workaround then, and have it so if needed you can click on what you selected and either remove it or edit it? Edited January 23, 2006 by vollyman The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Bert Posted January 23, 2006 Author Share Posted January 23, 2006 (edited) @Frost: If I understand this right, I can use listview to do this. I took some code you wrote and made a small change on line 16 and 17 to see if I can cange the color. It worked, but it changes the color on every line. Is there a way to change the color on just one line? CODE#include <GuiConstants.au3> #include <GuiListview.au3> _Main() Func _Main() Local $editCtrl = "Edit1";name of the Edit control that pops up when edit a listitem.... Local $editFlag = 0, $listview, $Gui, $start, $diff, $doubleclicked, $msg $Gui = GUICreate("Edit-able ListViewItems") $CloseButton = GUICtrlCreateButton("Close", 300, 300, 100, 20) $listview = GUICtrlCreateListView("Items", 10, 10, 300, 200, $LVS_EDITLABELS);Important Style!!! ; Populate list and make it wide enough to see For $i = 1 To 10 $main = GUICtrlCreateListViewItem("single quick twice or press F2, then press Enter", $listview) GUICtrlSetColor($main, 0xff0000) Next GUICtrlSendMsg($listview, 0x101E, 0, -1);$listview, LVM_SETCOLUMNWIDTH, 0, resize to widest value GUISetState(@SW_SHOW) $dll = DllOpen("user32.dll") While 1 $msg = GUIGetMsg(1) _MonitorEditState($Gui, $editCtrl, $editFlag, $listview, $dll, $msg, $start, $diff, $doubleclicked) Select Case $msg[0] = $GUI_EVENT_CLOSE Or $msg[0] = $CloseButton Exit Case Else EndSelect WEnd DllClose($dll) EndFunc ;==>_Main Func _MonitorEditState(ByRef $h_gui, ByRef $editCtrl, ByRef $editFlag, ByRef $listview, ByRef $dll, ByRef $msg, ByRef $start, ByRef $diff, ByRef $doubleclicked) If $msg[0] = $GUI_EVENT_PRIMARYDOWN Then Local $focus = ControlGetFocus(WinGetTitle($h_gui)) Local $pos = ControlGetPos($h_gui, "", $focus) Local $mpos = MouseGetPos() If ControlCommand($h_gui, "", $editCtrl, "IsVisible", "") Then If $mpos[0] < $pos[0] Or $mpos[0] > $pos[0] + $pos[2] Or _ $mpos[1] < $pos[1] Or $mpos[1] > $pos[1] + $pos[3] Then CancelEdit($listview) $editFlag = 0 EndIf Else If (StringInStr($focus, "SysListView3")) Then $diff = TimerDiff($start) ; Read the current mouse-doubleclick-settings from registry $mousespeed = RegRead("HKCU\Control Panel\Mouse", "DoubleClickSpeed") If $mousespeed = "" Then $mousespeed = 700 If $diff < $mousespeed And $doubleclicked = 0 Then Rename($listview) $doubleclicked = 1 Else $doubleclicked = 0 EndIf $start = TimerInit() EndIf EndIf EndIf Local $pressed = _IsPressedMod($dll) If $editFlag And $pressed = 13 Then; pressed enter Update($h_gui, $editCtrl, $listview) ElseIf $editFlag And $pressed = 27 Then; pressed esc CancelEdit($listview) $editFlag = 0 ElseIf Not $editFlag And $pressed = 113 Then; pressed f2 Rename($listview) $editFlag = 1 EndIf Sleep(50) If ControlCommand($h_gui, "", $editCtrl, "IsVisible", "") Then If $editFlag = 0 Then $editFlag = 1 Rename($listview) EndIf Else $editFlag = 0 EndIf EndFunc ;==>_MonitorEditState Func Rename(ByRef $listview) Local $itemIndex = _GUICtrlListViewGetCurSel ($listview) GUICtrlSendMsg($listview, $LVM_EDITLABEL, $itemIndex, 0) HotKeySet("{Enter}", "Enter") EndFunc ;==>Rename Func Enter() ; just a dummy function EndFunc ;==>Enter Func Update(ByRef $h_gui, ByRef $editCtrl, ByRef $listview) Local $newText = ControlGetText($h_gui, "", $editCtrl) Local $item = GUICtrlRead($listview) GUICtrlSetData($item, $newText) HotKeySet("{Enter}") Send("{Enter}");quit edit mode $editFlag = 0 $update = 0 EndFunc ;==>Update Func CancelEdit(ByRef $listview) GUICtrlSendMsg($listview, $LVM_CANCELEDITLABEL, 0, 0) EndFunc ;==>CancelEdit Func _IsPressedMod($dll = "user32.dll") Local $aR, $bRv, $hexKey, $i For $i = 8 To 128 $hexKey = '0x' & Hex($i, 2) $aR = DllCall($dll, "int", "GetAsyncKeyState", "int", $hexKey) If $aR[0] <> 0 Then Return $i Next Return 0 EndFunc ;==>_IsPressedMod Edited January 23, 2006 by vollyman The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
GaryFrost Posted January 23, 2006 Share Posted January 23, 2006 your loop set the color on every item For $i = 1 To 10 $main = GUICtrlCreateListViewItem("single quick twice or press F2, then press Enter", $listview) GUICtrlSetColor($main, 0xff0000) Next GUICtrlSendMsg($listview, 0x101E, 0, -1);$listview, LVM_SETCOLUMNWIDTH, 0, resize to widest value it's up to you how many to set the color on SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Bert Posted January 24, 2006 Author Share Posted January 24, 2006 My buddy came up with this. It does what we need: CODE#include <GUIConstants.au3> #include <GuiListView.au3> GLOBAL $MESSAGE = "This text will stay black" GUICreate("My GUI list"); will create a dialog box that when displayed is centered $add=GUICtrlCreateButton ("Add Red", 64,32,75,25) $button = GUICtrlCreateButton ("Add Black", 64,68,75,25) $clear=GUICtrlCreateButton ("Clear", 64,102,75,25) $mylist=GUICtrlCreateListView (' ', 176,32,210,97, BitOR($LVS_REPORT, $LVS_NOCOLUMNHEADER)) _GUICtrlListViewSetColumnWidth($mylist, 0, 300) GUICtrlCreateListViewItem("black black, black", $mylist) GUICtrlCreateListViewItem($MESSAGE, $mylist) $close=GUICtrlCreateButton ("my closing button", 64,160,175,25) GUISetState () $msg = 0 ;$color2 = GUICtrlSetColor($text1,0x000000) While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select case $msg = $add GUICtrlCreateListViewItem("This text needs to be red|", $mylist) GUICtrlSetColor(-1,0xFF0000) case $msg = $clear _GUICtrlListViewDeleteAllItems($mylist) case $msg = $button GUICtrlCreateListViewItem("This text needs to be black|", $mylist) Case $msg = $close MsgBox(0,"", "the closing button has been clicked",2) Exit EndSelect Wend @Frost: that script you made is really cool! Nice work. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now