Help me with RICHEDIT5

Post Reply
User avatar
Willi Quintana
Posts: 1070
Joined: Sun Oct 09, 2005 10:41 pm
Location: Cusco - Perú
Contact:

Help me with RICHEDIT5

Post by Willi Quintana »

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

User avatar
Antonio Linares
Site Admin
Posts: 44515
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Help me with RICHEDIT5

Post by Antonio Linares »

Dear Willi,

Code: Select all | Expand

// 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
User avatar
Willi Quintana
Posts: 1070
Joined: Sun Oct 09, 2005 10:41 pm
Location: Cusco - Perú
Contact:

Re: Help me with RICHEDIT5

Post by Willi Quintana »

Funciono,,
GRacias Antonio

Post Reply