Jump to content

Change Text Color in RichEdit--Solved


Beege
 Share

Recommended Posts

Anyone know how I can append different color text to a RichEdit without changing all the color of all the previous text? Any help would be great. Thanks

#include <ButtonConstants.au3>
#Include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$GUI = GUICreate("Form1", 405, 333)
$btRed = GUICtrlCreateButton("RED", 26, 282, 81, 33, $WS_GROUP)
$btGreen = GUICtrlCreateButton("Green", 162, 282, 81, 33, $WS_GROUP)
$btBlue = GUICtrlCreateButton("Blue", 298, 282, 81, 33, $WS_GROUP)
$Input1 = GUICtrlCreateInput("Some Text to append", 16, 248, 377, 21)
$RichEdit = _GUICtrlRichEdit_Create($GUI, "" & @CRLF, 32,  8, 345, 225, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY))
GUISetState(@SW_SHOW)

Global Const $cGreen = '65280'
Global Const $cRed = '255'
Global Const $cBlue = '16711680'

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GUICtrlRichEdit_Destroy($RichEdit)
            Exit
        Case $btBlue
            _GuiCtrlRichEdit_SetCharColor($RichEdit, $cBlue)
            _GUICtrlRichEdit_AppendText($RichEdit, GUICtrlRead($Input1) & @CRLF)
        Case $btRed
            _GuiCtrlRichEdit_SetCharColor($RichEdit, $cRed)
            _GUICtrlRichEdit_AppendText($RichEdit, GUICtrlRead($Input1) & @CRLF)
        Case $btGreen
            _GuiCtrlRichEdit_SetCharColor($RichEdit, $cGreen)
            _GUICtrlRichEdit_AppendText($RichEdit, GUICtrlRead($Input1) & @CRLF)
    EndSwitch
WEnd
Edited by Beege
Link to comment
Share on other sites

Link to comment
Share on other sites

Got it! Thanks again for looking ;)

#include <ButtonConstants.au3>
#Include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$GUI = GUICreate("Form1", 405, 333)
$btRed = GUICtrlCreateButton("RED", 26, 282, 81, 33, $WS_GROUP)
$btGreen = GUICtrlCreateButton("Green", 162, 282, 81, 33, $WS_GROUP)
$btBlue = GUICtrlCreateButton("Blue", 298, 282, 81, 33, $WS_GROUP)
$Input1 = GUICtrlCreateInput("", 16, 248, 377, 21)
$RichEdit = _GUICtrlRichEdit_Create($GUI, "" & @CRLF, 32,  8, 345, 225, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY))
GUISetState(@SW_SHOW)

Global Const $cGreen = '65280'
Global Const $cRed = '255'
Global Const $cBlue = '16711680'

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GUICtrlRichEdit_Destroy($RichEdit)
            Exit
        Case $btBlue
            _GUICtrlRichEdit_AppendText($RichEdit, @CRLF & GUICtrlRead($Input1))
            _GuiCtrlRichEdit_SetSel($RichEdit, _GuiCtrlRichEdit_GetFirstCharPosOnLine($RichEdit), -1, True)
            _GuiCtrlRichEdit_SetCharColor($RichEdit, $cBlue)
        Case $btRed
            _GUICtrlRichEdit_AppendText($RichEdit, @CRLF & GUICtrlRead($Input1))
            _GuiCtrlRichEdit_SetSel($RichEdit, _GuiCtrlRichEdit_GetFirstCharPosOnLine($RichEdit), -1, True)
            _GuiCtrlRichEdit_SetCharColor($RichEdit, $cRed)
        Case $btGreen
            _GUICtrlRichEdit_AppendText($RichEdit, @CRLF & GUICtrlRead($Input1))
            _GuiCtrlRichEdit_SetSel($RichEdit, _GuiCtrlRichEdit_GetFirstCharPosOnLine($RichEdit), -1, True)
            _GuiCtrlRichEdit_SetCharColor($RichEdit, $cGreen)
    EndSwitch
WEnd
Edited by Beege
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...