FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Help me with RICHEDIT5
Posts: 1070
Joined: Sun Oct 09, 2005 10:41 PM

Help me with RICHEDIT5

Posted: Thu Jun 11, 2026 11:03 PM

Good morning everyone... I'm starting with the RichEdit5 class, and what I need is to select a phrase and then, with a button click, change the selected text to blue or red.

Thanks

Posts: 44508
Joined: Thu Oct 06, 2005 05:47 PM

Re: Help me with RICHEDIT5

Posted: Fri Jun 12, 2026 04:19 AM

Dear Willi,

// RichEdit5 - select text then click button to change color
#include "FiveWin.ch"
#include "RichEdi5.ch"

#define BTN_Y     440   // button row from top
#define BTN_H      30   // button height
#define MARGIN      5   // edge margin

function Main()
   local oWnd, oRich, oBtnBlue, oBtnRed, oBtnBlack, oBtnBold, oBtnItalic
   local cText := "Select any phrase in this text." + CRLF + ;
                  "Then click Blue or Red button." + CRLF + ;
                  "The selected text will change color." + CRLF + ;
                  "Other formatting (bold, italic, size) stays."

   DEFINE WINDOW oWnd TITLE "RichEdit5 SetSelColor Test" ;
      FROM 0, 0 TO 520, 700 PIXEL

   @ MARGIN, MARGIN RICHEDIT5 oRich VAR cText SIZE 680, 420 PIXEL OF oWnd

   @ BTN_Y, 10 BUTTON oBtnBlue PROMPT "Blue" SIZE 80, BTN_H PIXEL OF oWnd ;
      ACTION oRich:SetTextColor( CLR_BLUE )

   @ BTN_Y, 100 BUTTON oBtnRed PROMPT "Red" SIZE 80, BTN_H PIXEL OF oWnd ;
      ACTION oRich:SetTextColor( CLR_RED )

   @ BTN_Y, 190 BUTTON oBtnBlack PROMPT "Black" SIZE 80, BTN_H PIXEL OF oWnd ;
      ACTION oRich:SetTextColor( CLR_BLACK )

   @ BTN_Y, 300 BUTTON oBtnBold PROMPT "Bold" SIZE 80, BTN_H PIXEL OF oWnd ;
      ACTION ( oRich:SetBold( ! oRich:GetCharFormat()[ 5 ] == 700 ), ;
               oRich:SetFocus() )

   @ BTN_Y, 390 BUTTON oBtnItalic PROMPT "Italic" SIZE 80, BTN_H PIXEL OF oWnd ;
      ACTION ( oRich:SetItalic( ! oRich:GetCharFormat()[ 6 ] ), ;
               oRich:SetFocus() )

   ACTIVATE WINDOW oWnd CENTERED ;
      ON RESIZE ResizeCtrls( oWnd, oRich, oBtnBlue, oBtnRed, oBtnBlack, oBtnBold, oBtnItalic )

return nil

//----------------------------------------------------------------------------//

static function ResizeCtrls( oWnd, oRich, oBtnBlue, oBtnRed, oBtnBlack, ;
                             oBtnBold, oBtnItalic )

   local nW     := oWnd:nWidth
   local nH     := oWnd:nHeight
   local nBtnY  := nH - BTN_H - 50  // buttons 50px from bottom
   local nRichH := nBtnY - MARGIN - 5

   // RichEdit fills width and stretches to button row (5px gap right + bottom)
   oRich:SetSize( nW - MARGIN * 2 - 15, nRichH, .T. )

   // Buttons anchor to bottom, keep original X positions
   oBtnBlue:Move( nBtnY, oBtnBlue:nLeft,,, .T. )
   oBtnRed:Move( nBtnY, oBtnRed:nLeft,,, .T. )
   oBtnBlack:Move( nBtnY, oBtnBlack:nLeft,,, .T. )
   oBtnBold:Move( nBtnY, oBtnBold:nLeft,,, .T. )
   oBtnItalic:Move( nBtnY, oBtnItalic:nLeft,,, .T. )

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1070
Joined: Sun Oct 09, 2005 10:41 PM

Re: Help me with RICHEDIT5

Posted: Sat Jun 13, 2026 06:24 PM

Funciono,, GRacias Antonio

Continue the discussion