shaggy89 Posted August 31, 2015 Posted August 31, 2015 HI all, Just looking for a way that i can change the color of a string of texte.g$text "I need to be the color red"simple im sure but i cant seem to find it. the help file saysLocal $iRedColor = _ColorGetRed(0x8080ff)so i tried$text =($iRedColor, "I need to be the color red")any help would be great ThanksShaggs
water Posted August 31, 2015 Posted August 31, 2015 Where do you need to change the color? In a GUI, a Word document, somewhere else? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Celtic88 Posted August 31, 2015 Posted August 31, 2015 (edited) https://www.autoitscript.com/autoit3/docs/libfunctions/_GUICtrlRichEdit_SetCharColor.htm Edited August 31, 2015 by Celtic88
shaggy89 Posted August 31, 2015 Author Posted August 31, 2015 Where do you need to change the color? In a GUI, a Word document, somewhere else?will be used to display what the user has typed. so user would type in text via a gui using GUICtrlCreateInput and gets passed into the GUICtrlCreateEdit so that would be displayed in backbut when a user presses a button i wanted a pre-canned message displayed in red in the GUICtrlCreateEdit field
jguinch Posted August 31, 2015 Posted August 31, 2015 Helpfile : GUICtrlSetColor Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Moderators Melba23 Posted August 31, 2015 Moderators Posted August 31, 2015 shaggy89,If you want only specific lines to be displayed in red then you will need to use a RichEdit control - GUICtrlSetColor will change all text in a simple Edit control.M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
shaggy89 Posted August 31, 2015 Author Posted August 31, 2015 shaggy89,If you want only specific lines to be displayed in red then you will need to use a RichEdit control - GUICtrlSetColor will changed all text in a simple Edit control.M23M23 you beat me to the puch. I looked at help file and @jguinch the help file says "The control identifier (controlID) as returned by a GUICtrlCreate...() function, or -1 for the last created control."as you can see mine is a pre made string will look Into rich edit Shortly cheers
shaggy89 Posted August 31, 2015 Author Posted August 31, 2015 M23 could you give an example how this would work im my situation
Moderators Melba23 Posted August 31, 2015 Moderators Posted August 31, 2015 shaggy98,I use this function to write to RichEdit controls as it allows you to adjust the font size and attributes as well as the colour - here we leave the size and attributes as default and only adjust the colour:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiRichEdit.au3> $hGui = GUICreate("RichEdit Test", 320, 350) $hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 10, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) GUISetState() Sleep(1000) ; Write in black _GUICtrlRichEdit_WriteLine($hRichEdit, "I am in BLACK" & @CRLF, Default, Default, 0x000000) Sleep(2000) ; Write in red _GUICtrlRichEdit_WriteLine($hRichEdit, "I am in RED" & @CRLF, Default, Default, 0xFF0000) Sleep(2000) ; And back to black _GUICtrlRichEdit_WriteLine($hRichEdit, "I am back in BLACK" & @CRLF, Default, Default, 0x000000) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete() Exit EndSwitch WEnd Func _GUICtrlRichEdit_WriteLine($hWnd, $sText, $iIncrement = 0, $sAttrib = "", $iColor = -1) ; Count the @CRLFs StringReplace(_GUICtrlRichEdit_GetText($hWnd, True), @CRLF, "") Local $iLines = @extended ; Adjust the text char count to account for the @CRLFs Local $iEndPoint = _GUICtrlRichEdit_GetTextLength($hWnd, True, True) - $iLines ; Add new text _GUICtrlRichEdit_AppendText($hWnd, $sText & @CRLF) ; Select text between old and new end points _GuiCtrlRichEdit_SetSel($hWnd, $iEndPoint, -1) ; Convert colour from RGB to BGR $iColor = Hex($iColor, 6) $iColor = '0x' & StringMid($iColor, 5, 2) & StringMid($iColor, 3, 2) & StringMid($iColor, 1, 2) ; Set colour If $iColor <> -1 Then _GuiCtrlRichEdit_SetCharColor($hWnd, $iColor) ; Set size If $iIncrement <> 0 Then _GUICtrlRichEdit_ChangeFontSize($hWnd, $iIncrement) ; Set weight If $sAttrib <> "" Then _GUICtrlRichEdit_SetCharAttributes($hWnd, $sAttrib) ; Clear selection _GUICtrlRichEdit_Deselect($hWnd) EndFuncPlease ask if you have any further questions.M23 Parsix and Skeletor 2 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
kylomas Posted August 31, 2015 Posted August 31, 2015 shaggy89,Another way to slice that banana...(1st time using rich edit so beware)expandcollapse popup#include <EditConstants.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <GuiRichEdit.au3> #include <array.au3> #AutoIt3Wrapper_Add_Constants=n Local $gui010 = GUICreate('RichEdit Example') Local $aSize = WinGetClientSize($gui010) Local $lbl010 = GUICtrlCreateLabel('Enter Your Data', 20, 20, 100, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE)) Local $inp010 = GUICtrlCreateInput('', 130, 20, 250, 20) Local $edt010 = _GUICtrlRichEdit_Create($gui010, '', 20, 50, 360, 310, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY)) Local $btn010 = GUICtrlCreateButton('Button for the User to Press', 20, $aSize[1] - 30, $aSize[0] - 40, 20) GUICtrlSetState($inp010, $GUI_FOCUS) GUISetState() Local $message = '>>>>> My Pre-Canned Message <<<<<' & @CRLF While 1 Switch GUIGetMsg() Case $gui_event_close _GUICtrlRichEdit_Destroy($edt010) Exit Case $btn010 _GUICtrlRichEdit_SetCharColor($edt010, 0x000000ff) ; set color red (BBGGRR format) _GUICtrlRichEdit_SetFont($edt010, 10) ; set size _GUICtrlRichEdit_SetCharAttributes($edt010, '+bo') ; set bold _GUICtrlRichEdit_AppendText($edt010, $message) ; write line GUICtrlSetState($inp010, $GUI_FOCUS) Case $inp010 _GUICtrlRichEdit_AppendText($edt010, GUICtrlRead($inp010) & @CRLF) GUICtrlSetState($inp010, $GUI_FOCUS) GUICtrlSetData($inp010, '') EndSwitch WEndkylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
UEZ Posted August 31, 2015 Posted August 31, 2015 One more RTF example: https://www.autoitscript.com/forum/topic/165413-colored-substrings-in-gui-edit/?do=findComment&comment=1207984 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
shaggy89 Posted August 31, 2015 Author Posted August 31, 2015 So change all GuiEdit to GuiRtfEdit and then set colors?Just would like to say a big thanks to all for help.
shaggy89 Posted September 2, 2015 Author Posted September 2, 2015 (edited) hi all, Ive been trying to get RichText working but am having an issue.If I useFunc Print($txtMsg) _GUICtrlRichEdit_AppendText($hEdit, @CRLF&$txtMsg) EndFunc ;==> Printnothing works but if I remove the@CRLFthe message is displayed but not on a new line. what am i missing ?whole script expandcollapse popup#cs ---------------------------------------------------------------------------- DELmE's LanChat #ce ---------------------------------------------------------------------------- ;include files #include <GuiConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <GuiEdit.au3> #include <GuiRichEdit.au3> ;define variables Global $hGui, $hEdit, $hInp, $hBtn, $username, $rsock, $ssock, $recv Global $port = 7892 Global $Broadcast = StringLeft(@IPAddress1, StringInStr(@IPAddress1, ".", 0, 3)) & "255" ;start main function _main() Func _main() ;get username $username = @UserName ;create gui $hGui = GUICreate("LanChat and Assist",585,503) $hEdit = _GUICtrlRichEdit_Create($hGui,"Welcome to LanChat and Assist",0,0,500,480,BitOR($ES_READONLY,$ES_WANTRETURN,$WS_VSCROLL,$ES_AUTOVSCROLL)) _GUICtrlEdit_SetLimitText($hEdit,99999999999999) $hInp = GUICtrlCreateInput("",0,480,470,20) $hBtn = GUICtrlCreateButton("Send",470,480,30,20,$BS_DEFPUSHBUTTON) $AFK = GUICtrlCreateButton("AFK", 505, 50, 75, 25,$BS_DEFPUSHBUTTON) $bak = GUICtrlCreateButton("BAK", 505, 100, 75, 25,$BS_DEFPUSHBUTTON) $exit= GUICtrlCreateButton("Close", 505, 470, 75, 25,$BS_DEFPUSHBUTTON) ;display gui GUISetState() ;start winsock for udp UDPStartup() ;bind a socket to the port for listening $rsock = UDPBind(@IpAddress1,$port) If @error <> 0 Then Exit ;send message informing of online status SendMsg("-"&$username&" has come online.") ;start gui loop Do $recv = UDPRecv($rsock,1024) If $recv <> "" Then Print($recv) EndIf $msg = GUIGetMsg() If $msg = $hBtn Then $buffer = GUICtrlRead($hInp) If $buffer <> "" Then GUICtrlSetData($hInp,"") SendMsg("<"&$username&">: "&$buffer) EndIf EndIf If $msg = $AFK Then $buffer = "AFK " ; make red If $buffer <> "" Then GUICtrlSetData($hInp,"") SendMsg("<"&$username&">: "&$buffer) EndIf EndIf If $msg = $bak Then $buffer = "BAK " ; make green If $buffer <> "" Then GUICtrlSetData($hInp,"") SendMsg("<"&$username&">: "&$buffer) EndIf EndIf EndIf If $msg = $exit Then $msg = $GUI_EVENT_CLOSE EndIf Until $msg = $GUI_EVENT_CLOSE Exit EndFunc ;==> _main Func SendMsg($txtMsg) $ssock = UDPOpen($Broadcast,$port) If @error = 0 Then UDPSend($ssock,$txtMsg) EndIf UDPCloseSocket($ssock) EndFunc ;==> SendMsg Func Print($txtMsg) _GUICtrlRichEdit_AppendText($hEdit, @CRLF&$txtMsg) EndFunc ;==> Print Func OnAutoItExit() ;send message informing of offline status SendMsg("-"&$username&" has gone offline.") UDPShutdown() EndFunc ;==> OnAutoItExit Edited September 2, 2015 by shaggy89 Now on a PC
kylomas Posted September 2, 2015 Posted September 2, 2015 shaggy89,Please post the problem code or a reproducer.kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
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