Spread Windows Forms 17
Spread Windows Forms 17.0 Product Documentation / Developer's Guide / Spreadsheet Objects / Rich Text Editing
In This Topic
    Rich Text Editing
    In This Topic

    The Rich Text Editing feature in Spread for WinForms helps to render different text styles and add formulas in the worksheet. The IFeatures interface provides the RichTextEdit property to indicate whether the rich text is editable or not.

    The FarPoint.Win.Spread namespace provides the RichTextEditMode enumeration to indicate whether you can edit rich text in Spread worksheet. This enumeration provides three values:

    To use the rich text editing feature, enable the flat style mode in Spread, and set the RichTextEditMode to On.

    C#
    Copy Code
    // Flat style
    fpSpread1.LegacyBehaviors = LegacyBehaviors.None;
    // Enable rich text editing
    fpSpread1.Features.RichTextEdit = RichTextEditMode.On;
    

    Font Dialog

    You can show the built-in Font editor dialog to edit font settings for the currently selected text using the FormatCells method of the BuiltInDialogs class. To learn more about the dialog, see Working with BuiltInDialogs.

    C#
    Copy Code
    if (fpSpread1.EditingControl is IRichTextEditor richTextEditor)
    {
        BuiltInDialogs.FormatCells(richTextEditor);
    }
    

    You can manipulate the font of the text while editing a cell in the worksheet using the Format Cells dialog at runtime, for example, you can change the font type, font style, text size, text color, text effects, etc.

    Spread allows you to manipulate the rich text editor using the IRichTextEditor interface. Here is an example of toggling the bold settings when the user edits a cell.

    C#
    Copy Code
    private void ToggleBold(FpSpread spread)
    {
        if (spread.EditingControl is IRichTextEditor richTextEditor)
        {
           GrapeCity.Spreadsheet.Font font = GrapeCity.Spreadsheet.Font.Empty;
           font.Bold = !richTextEditor.SelectionFont.Bold;
           richTextEditor.ApplyFont(font, -1, -1); //apply to current selected text
        }
    }
    

    Insert Function dialog

    You can show the Insert Function dialog using the ToggleInsertFunction property of the BuiltInDialogs class. To learn more about the dialog, see Working with BuiltInDialogs.

    The Spread Designer UI provides many rich text editing features like Intellisense support, auto-complete, pick from dropdown list, etc. You can learn more about the rich text editing feature in Spread Designer from the Rich Text Editing topic in the Designing in the Data Area section.