Jump to content
Sign in to follow this  

Rich Text Edits

Recommended Posts


To create a RichText Edit use the following function: (help file)

#include <GuiRichEdit.au3>
_GUICtrlRichEdit_Create($Window, $Text, $Left, $Top[, $Width [, $Height [, $Style [, $ExStyle ]]]])
;#   $Window : Which Window should the RichText Edit be in?
;#   $Text : Which Text should be in the RichText Edit?
;#   $Left : The RichText Edit's position from the left?
;#   $Top : The RichText Edit's position from the top?
;#   $Width : The RichText Edit's width
;#   $Height : The RichText Edit's height
;#   $Style : The RichText Edit's Styles
;#   $ExStyle : The RichText Edit's Extended Styles

To input text in another size / color / Bold / italic ... Check out Melba23s Helper

To read out your RichText Edit Use (help file)

#include <GuiRichEdit.au3>
_GUICtrlRichEdit_StreamToFile($Window, $Path [, $fIncludeCOM=True [, $iOpts=0 [, $iCodePage = 0]]])

Make sure NOT to save it as a txt!!!! Txt doesn't support rich text! Use .rtf (works best and should be supported by every computer)

To add something to your Edit, use (help file)

#include <GuiRichEdit.au3>
_GUICtrlRichEdit_AppendText($hWnd, $sText)

If you want to add something with a diffrent size or in bold or italic, again, check out Melba23s Helper

So Finally i have this example Code for you. (Doesnt use Any special text)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiRichEdit.au3>
#include <File.au3>
$Form1 = GUICreate("Test", 411, 300) ;Creates The GUI and makes it centered in the screen
Global $Edit1 = _GUICtrlRichEdit_Create($Form1, "", 8, 8, 393, 241, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) ;Creates The richtext edit and makes it global, so that every function can read it out
GUICtrlSetData(-1, "")
$Button1 = GUICtrlCreateButton("Input Something", 40, 264, 129, 25) ;creates a button
$Button2 = GUICtrlCreateButton("Save Text", 176, 264, 113, 25) ;creates a button
$Button3 = GUICtrlCreateButton("Close", 304, 264, 89, 25) ;creates a button
GUISetState(@SW_SHOW) ;Makes the GUI visible
While 1
    $msg = GUIGetMsg() ;gets the GUI "changes"
    Switch $msg
        Case $GUI_EVENT_CLOSE ;on click on the X
            _GUICtrlRichEdit_Destroy($Edit1) ;VERY IMPORTANT!
        Case $Button1
            $input = InputBox("Input your text here", "Input your text that you want to add to the edit here") ;shows an inputbox
            _GUICtrlRichEdit_AppendText($Edit1, $Input & @CRLF) ;adds the text fron the inputbox to the Edit
        Case $Button2
            _save() ;calls function _save()
        Case $Button3
            _GUICtrlRichEdit_Destroy($Edit1) ;IMPORTANT before exit!
    EndSwitch ;Ends the switch
WEnd ;ends the while

Func _save()
    $MyDocsFolder = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}" ;Declares The variable $MyDocsFolder
    $savewhere = FileSaveDialog("Save to...", $MyDocsFolder,"Rich Text Files (*rtf)", 2) ;opens a dialog where you want to save your file
    If StringInStr($savewhere,".rtf") Then ;checks if the file extention is already there
        _FileCreate($savewhere);creates the file in directory selected (I'm not sure if it's necessary or not)
        $savetofile =  _GUICtrlRichEdit_StreamToFile($Edit1, $savewhere)
    Else ;else adds file extention
        $savewhere = $savewhere & ".rtf"
        _FileCreate($savewhere) ;creates the file in directory selected (I'm not sure if it's necessary or not)
        $savetofile =  _GUICtrlRichEdit_StreamToFile($Edit1, $savewhere)
    EndIf ;Ends the if
  • Like 1

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.