Jump to content
RaiNote

Multiple Colours one Line

Recommended Posts

RaiNote

Hi,

is there a way to convert this Code to an Code which can make more than one Color in one line?

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)

EndFunc

 


  • 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~

 

Share this post


Link to post
Share on other sites
Danyfirex

just simple pass string with @crlf  like  "Hola" & @CRLF & "Como estas"

 

Saludos

Edited by Danyfirex
  • Like 1

Share this post


Link to post
Share on other sites
RaiNote

ok thx~


  • 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~

 

Share this post


Link to post
Share on other sites
Melba23

RaiNote,

Just remove the @CRLFs:

#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_WriteText($hRichEdit, "I am in BLACK ", Default, Default, 0x000000)

Sleep(2000)

; Write in red
_GUICtrlRichEdit_WriteText($hRichEdit, "I am in RED " & @CRLF, Default, Default, 0xFF0000)

Sleep(2000)

; And back to black
_GUICtrlRichEdit_WriteText($hRichEdit, "I am back in BLACK ", Default, Default, 0x000000)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            Exit
    EndSwitch



WEnd



Func _GUICtrlRichEdit_WriteText($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) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    ; 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)

EndFunc

M23

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
RaiNote

Thanks Melba~


  • 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~

 

Share this post


Link to post
Share on other sites
kylomas

Another way to look at it.  Set the char/string attributes then write to the control...(as opposed to write, select, change, deselect)...

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

local $sString1 = 'I am a piece of text that wants to be multi-colored.  Every letter is a different color.'
local $sString2 = 'I am a piece of text that wants to be multi-colored.  Every word is a different color.'
local $aColors = [0xff0000,0x00ff00, 0x0000ff], $LastColor, $Color

$hGui = GUICreate("RichEdit Test", 320, 350)

$hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 10, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))

GUISetState()

for $i = 0 to stringlen($sString1)
    ; ensure successive unique color
    $Color = $aColors[random(0,2,1)]
    while $Color = $LastColor

        $Color = $aColors[random(0,2,1)]
    wend
    $LastColor = $Color
    _GUICtrlRichEdit_SetCharColor($hRichEdit,$Color)
    _GUICtrlRichEdit_AppendText($hRichEdit,stringmid($sString1,$i,1))
next
    _GUICtrlRichEdit_AppendText($hRichEdit,@crlf)

local $aTemp = stringsplit($sString2, ' ', 2)
for $i = 0 to ubound($aTemp) - 1
    ; ensure successive unique color
    $Color = $aColors[random(0,2,1)]
    while $Color = $LastColor

        $Color = $aColors[random(0,2,1)]
    wend
    $LastColor = $Color
    _GUICtrlRichEdit_SetCharColor($hRichEdit,$Color)
    _GUICtrlRichEdit_AppendText($hRichEdit,$aTemp[$i] & ' ')
next

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            Exit
    EndSwitch



WEnd

kylomas

  • Like 1

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      Hello
      I have a query please
      It is about windows file explorer
      If i design a tool in autoit language to delete files for example
      and i  added it in the context menu in File Explorer
      If i right-click on any file And you choose the tool, it will be get the path of the selected file or folder
      The problem here is
      If i select a set of files or folders
      it only detect the first one
      The code that i  used is
      if $CMDLine[0] = 0 then
      msgBox(16, "error", "you don't selecte any files")
      exit
      else
      for $i = 1 to $CMDLine[0]
      msgBox(0, "files", $CMDLine[$i]
      next
      endIf
      exit
    • nacerbaaziz
      By nacerbaaziz
      Hello
      I have an inquiry from you
      I have a file path  with commands line
      Is there a way to separate the path from the commands line?
      I want the result in an array
      for example
      $path = '"c:\NVDA\NVDA slav Portable 1\NVDA.exe" -r -m -path="d:\NVDA Path\Portable"'
      there are any method to separate this text?
      i want the result to be as that
      $array[1] = "c:\NVDA\NVDA slav Portable 1\NVDA.exe"
      $array[2] = '-r -m -path="d:\NVDA Path\Portable"'
      Thanks in advance
      am Waiting for your answers
    • ur
      By ur
      In the autoit file, if we add multiple libraries (both internal and custom created one)
       
      When we compile the code and run the exe, some time we are getting runtime errors.
      But the line number of error is not showing the exact line number, might be it is including the line number count of libraries also.
      Can you please suggest how to get the exact error line number.
      So, it will be useful for debugging.
    • nacerbaaziz
      By nacerbaaziz
      Hello my friends
      I have an inquiry after your permission
      I found a function to get the special line commands for any operation
      It requires the name of the process to be searched
      I want to use it to know the process
      Is this possible with this function
      Here is the code
       
      Func commandLineGet($proc, $strComputer=".")
      dim $array[1]
      local $ArrayNumber
      local $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
      local $oProcessColl = $oWMI.ExecQuery("Select * from Win32_Process where Name= " & '"'& $Proc & '"')
      local $Process
      For $Process In $oProcessColl
      $Process = $Process.Commandline
          ReDim $Array[UBound($Array)+1]
      $ArrayNumber = UBound($Array)-1
      $array[$ArrayNumber] = $Process
      Next
      $ArrayNumber = UBound($Array)-1
      $array[0] = $ArrayNumber
      return $array
      EndFunc
    • Miliardsto
      By Miliardsto
      Im creating a tab
      Global $Tab1 = GUICtrlCreateTab(30, 30, 600, 420, $TCS_BUTTONS, -1) And what we see in the function reference:
      https://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateTab.htm
      GUICtrlCreateTab ( left, top [, width [, height [, style = -1 [, exStyle = -1]]]] ) ok in 5 arg I got $TCS_BUTTONS
      But How can I use multiple args like this below
      Global $Tab1 = GUICtrlCreateTab(30, 30, 600, 420, [$TCS_BUTTONS, $TCS_MULTILINE], -1)  
×