Sign in to follow this  
Followers 0
Beege

Change Text Color in RichEdit--Solved

5 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



Check out Betapad. Every function there was native to the COM object, no UDFs. If you need help, I am the creator of it, so just PM me.

Also, it will not run on the latest versions of AutoIt, so some things will need to change.

Share this post


Link to post
Share on other sites

Looks pretty cool. Ill be sure to check that out.

Share this post


Link to post
Share on other sites

Looks pretty cool. Ill be sure to check that out.

Thanks! There is also the forum thread you can read here.

I remember writing this when I started AutoIt... Ahh the good old days. It's probably very bad coding. It was a somewhat joint effort between myself and another member ;)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

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