Jump to content

Problem with RichEdit


Recommended Posts

Hi,

I'm trying to make an HTML editor, but I have a problem. I don't know how I can search a part of a text in the editor and set it a color... for example, if I write <html> on the editor, I have to change it's font color like other editors... how can I do this?

 

Thanks for the help.

Link to comment
Share on other sites

Try:

#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("Input text here to add color", 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

From: 

 

Advanced: https://sourceforge.net/projects/betapad/files/latest/download?source=typ_redirect

Regards,
 

Link to comment
Share on other sites

Just now, Trong said:

Try:

#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("Input text here to add color", 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

From: 

 

Advanced: https://sourceforge.net/projects/betapad/files/latest/download?source=typ_redirect

Hi, thanks for the help but it is not what I need.

While i write on the editor the program have to find automatically the word <html> and set it a color...

Link to comment
Share on other sites

If you're wanting to use html like tags (or even forum tags) to set text attributes you have to parse the string yourself and extract it. You can take a look at this I wrote a while back

 

Parses an html like string and returns a 2d array with the attributes and color of the string (i.e., <color=#FF0000><b>This will appear bold and red</b> this will just be red</color>). Supports bold, italic, underline, strike, text color, background color, font name, and font size.

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...