Renderer Posted September 4, 2015 Share Posted September 4, 2015 Hello guys! Is there anyway to change the color for a specific word in autoit, because i want to create an IDE like interface text editor. I am waiting for your replies! Thanks in advance! Link to comment Share on other sites More sharing options...
Surya Posted September 4, 2015 Share Posted September 4, 2015 (edited) First of all Welcome to the Autoit Communityso what you are trying to do is to set colors to specific words in an edit box.am i right Edited September 4, 2015 by Surya No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition) Link to comment Share on other sites More sharing options...
RaiNote Posted September 4, 2015 Share Posted September 4, 2015 If u don't want to make all words gray/red/blue/.. then you have to use Richedit there should be some tutorials about it~ C++/AutoIt/OpenGL Easy Coder I will be Kind to you and try to help you till what you want isn't against the Forum Rules~ Link to comment Share on other sites More sharing options...
Renderer Posted September 5, 2015 Author Share Posted September 5, 2015 First of all Welcome to the Autoit Communityso what you are trying to do is to set colors to specific words in an edit box.am i rightyes,you're right! Link to comment Share on other sites More sharing options...
RaiNote Posted September 5, 2015 Share Posted September 5, 2015 (edited) 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) EndFunchttps://www.autoitscript.com/forum/topic/176557-change-color-of-text-string/?do=findComment&comment=1269308 This would be an example how i think how you want it and this source was made from Melba~ maybe you can find at this thread too some Infos.^^If u want to get fast and easy some Colors i refer to color-hex.com there u can easily search for Colors everything you have to do after you've found a Color replace the "#" with "0x" then it'll work~ Edited September 5, 2015 by RaiNote C++/AutoIt/OpenGL Easy Coder I will be Kind to you and try to help you till what you want isn't against the Forum Rules~ Link to comment Share on other sites More sharing options...
Renderer Posted September 5, 2015 Author Share Posted September 5, 2015 thanks! Link to comment Share on other sites More sharing options...
Surya Posted September 5, 2015 Share Posted September 5, 2015 This may help you : (CODE UNTESTED)expandcollapse popup#include <GUIConstantsEx.au3> #include <array.au3> #include <WindowsConstants.au3> #include <GuiRichEdit.au3> #include <ColorConstants.au3> $hGui = GUICreate("RichEdit Test", 320, 350) Local $ary[1][2] = [["red",$COLOR_RED]] ;ist element is the word is recognition word and the second element in the same coulmn is the colour Local $return_color = $COLOR_BLACK _ArrayDisplay($ary) $hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 10, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) GUISetState() While 1 ;ConsoleWrite(GUICtrlRead ($hRichEdit)) $editread = _GUICtrlRichEdit_GetText ($hRichEdit) $words = StringSplit($editread," ",2) $lastword = $words[UBound($words)-1] If _arrayFindin($lastword,$ary) Then _GUICtrlRichEdit_Setcolortext($hRichEdit,$lastword,$COLOR_RED) EndIf WEnd Func _arrayFindin($word,$ary) For $i = 0 to UBound ($ary) -1 If StringCompare ($lastword,$ary[$i][0]) = 0 Then Return True Next Return False EndFunc Func _GUICtrlRichEdit_Setcolortext($hWnd,$text,$iColor) $pos = StringLen(_GUICtrlRichEdit_GetText($hWnd)) - StringLen($text) _GuiCtrlRichEdit_SetSel($hWnd, $pos, -1) $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) _GUICtrlRichEdit_Deselect($hWnd) Sleep (150) _GuiCtrlRichEdit_SetCharColor($hWnd, $return_color) EndFuncthanks goes to RaiNote and melba32 because it is their code and i have slightly modified it to make it suitable for you feel free to ask for more help No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition) 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