JadeRichText Control Method Example

The following example shows a JadeRichText class click event method that dynamically creates and manipulates rich text in a control when the btnRTFByLogic button is clicked on the running form.

btnRTFByLogic_click(btn: Button input) updating;
vars
    str : String;
begin
    // Clear text box
    rtfRichText.text := "";

    // Change some text and end up with one
    // line reading "WednesdayFriday"
    rtfRichText.load("Monday", JadeRichText.Load_Append);
    rtfRichText.load("Tuesday", JadeRichText.Load_Append);
    rtfRichText.load("Wednesday",JadeRichText.Load_ReplaceAll);
    rtfRichText.load("Thursday", JadeRichText.Load_Append);
    rtfRichText.selStart := 9;
    rtfRichText.selLength := 5;
    rtfRichText.load("Fri", JadeRichText.Load_ReplaceSelection);

    // Change the font of ALL text so far, leaving font size,
    // color, and other attributes unchanged
    rtfRichText.setCharacterFormat(false,
                                   "Comic Sans MS",
                                   JadeRichText.CharacterFormat_Undefined,
                                   JadeRichText.CharacterFormat_Undefined,
                                   JadeRichText.CharacterFormat_Undefined,
                                   JadeRichText.CharacterFormat_Undefined,
                                   JadeRichText.CharacterFormat_Undefined,
                                   JadeRichText.CharacterFormat_Undefined);
    // Try some plain bullets
    rtfRichText.load(Cr, JadeRichText.Load_Append);
    rtfRichText.bulletStyle := JadeRichText.BulletStyle_Dot;
    rtfRichText.load("One" & Cr, JadeRichText.Load_Append);
    rtfRichText.load("Two" & Cr, JadeRichText.Load_Append);
    rtfRichText.load("Three" & Cr, JadeRichText.Load_Append);

    // Do numbered bullets, with text in its matching color
    rtfRichText.bulletStyle := JadeRichText.BulletStyle_Number;
    rtfRichText.setCharacterFormat(true,        // apply to selection
                   null,                        // use current font name
                   JadeRichText.CharacterFormat_Undefined,  // font size
                   #000000FF,                    // text color = Red
                   JadeRichText.CharacterFormat_NotSet,     // not bold
                   JadeRichText.CharacterFormat_Set,        // italic
                   JadeRichText.CharacterFormat_NotSet,     // no strikethru
                   JadeRichText.CharacterFormat_Set);       // underline
    rtfRichText.load("RED" & Cr, JadeRichText.Load_Append);
    rtfRichText.setCharacterFormat(true,
                                   null,
                                   16,
                                   #0000FF00,
                                   JadeRichText.CharacterFormat_Set,
                                   JadeRichText.CharacterFormat_NotSet,
                                   JadeRichText.CharacterFormat_Set,
                                   JadeRichText.CharacterFormat_NotSet);
    rtfRichText.load("GREEN" & Cr, JadeRichText.Load_Append);
    rtfRichText.selTextColor := 256;
    rtfRichText.setCharacterFormat(true,
                                   null,
                                   20,
                                   #00FF0000,
                                   JadeRichText.CharacterFormat_Undefined,
                                   JadeRichText.CharacterFormat_Undefined,
                                   JadeRichText.CharacterFormat_Set,
                                   JadeRichText.CharacterFormat_Set);
    rtfRichText.load("BLUE" & Cr, JadeRichText.Load_Append);

    // Create some text that exceeds the control width
    rtfRichText.bulletStyle := JadeRichText.BulletStyle_None;
    str := "1 2 3 4 5 6 7 8 9 0 ";
    str := str & str & str & str & str & str & str & str & str;
    rtfRichText.load(str & Cr, JadeRichText.Load_Append);

    // Try a different font
    rtfRichText.setCharacterFormat(true,
               "MS Sans Serif",  // Not a True Type font so cannot be scaled
               8.25,
               JadeRichText.CharacterFormat_AutoColor,   // System color
               JadeRichText.CharacterFormat_NotSet,
               JadeRichText.CharacterFormat_NotSet,
               JadeRichText.CharacterFormat_NotSet,
               JadeRichText.CharacterFormat_NotSet);

    // Different alignments, with left and right indents
    rtfRichText.setParagraphFormat(100, 75, 0, JadeRichText.Alignment_Left);
    rtfRichText.load("This is LEFT aligned" & Cr, JadeRichText.Load_Append);

    rtfRichText.setParagraphFormat(JadeRichText.ParagraphFormat_Undefined,
                                   JadeRichText.ParagraphFormat_Undefined,
                                   JadeRichText.ParagraphFormat_Undefined,
                                   JadeRichText.Alignment_Right);
    rtfRichText.load("This is RIGHT aligned" & Cr,JadeRichText.Load_Append);

    rtfRichText.setParagraphFormat(JadeRichText.ParagraphFormat_Undefined,
                                   JadeRichText.ParagraphFormat_Undefined,
                                   JadeRichText.ParagraphFormat_Undefined,
                                   JadeRichText.Alignment_Center);
    rtfRichText.load("This is CENTERED" & Cr, JadeRichText.Load_Append);

    // Justified text with hanging indent
    rtfRichText.setParagraphFormat(JadeRichText.ParagraphFormat_Undefined,
                                   JadeRichText.ParagraphFormat_Undefined,
                                   -20,
                                   JadeRichText.Alignment_Justify);
    rtfRichText.load("This is JUSTIFIED text. It also shows how text is "
                     & " displayed when paragraph indenting is used. Note "
                     & " that the first line indent value is relative to "
                     & " the left indent. Therefore you can create a "
                     & " hanging indent by using a negative first line "
                     & " indent value." & Cr,
                     JadeRichText.Load_Append);

    // Turn off hanging indent (or use the setParagraphFormat method)
    rtfRichText.firstLineIndent := 0;
    rtfRichText.alignment := JadeRichText.Alignment_Left;

    // Add a URL that is displayed as a link
    rtfRichText.autoURLDetect := true;
    rtfRichText.append(Cr & "www.jadeworld.com");

    // Replace all 'www.microsoft.com' with 'www.jadeworld.com'
    rtfRichText.replace("www.microsoft.com",
                        "www.jadeworld.com",
                        JadeRichText.Find_BeginningOfText,
                        JadeRichText.Find_EndOfText,
                        JadeRichText.Replace_ReplaceAll);

    // Insert a picture
    rtfRichText.append(Cr); // Make on a new line
    rtfRichText.insertObject("c:\schema\images\jadelogo.bmp", false, false);

    // Scroll the whole control up by 20 pixels
    rtfRichText.scrollVertPos := 20;

end;

The following image shows the result of this method in a JadeRichText control on a form when the btnRTFByLogic button is clicked.