Back to Devexpress

ICharacterProperties.Script Property

blazor-devexpress-dot-blazor-dot-richedit-dot-icharacterproperties.md

latest3.7 KB
Original Source

ICharacterProperties.Script Property

Returns the script format of characters.

Namespace : DevExpress.Blazor.RichEdit

Assembly : DevExpress.Blazor.RichEdit.v25.2.dll

NuGet Package : DevExpress.Blazor.RichEdit

Declaration

csharp
CharacterFormattingScript? Script { get; }

Property Value

TypeDescription
Nullable<CharacterFormattingScript>

The script format or null if at least two different characters use different script formats.

|

Available values:

NameDescription
Normal

Specifies that the text is not formatted as subscript or superscript.

| | Subscript |

Formats text as subscript.

| | Superscript |

Formats text as superscript.

|

Remarks

A cell stores its text formatting settings in the CharacterProperties property. The Script setting returns whether characters are superscript or subscript. Call the cell’s ChangePropertiesAsync method to apply a script format to all cell characters.

The following example removes subscript and superscript font attributes from all characters in a table:

razor
<DxRichEdit @ref="richEdit" />

@code {
    DxRichEdit richEdit;
    protected override async Task OnAfterRenderAsync(bool firstRender) {
        if (firstRender)
            try {
                await InitializeDocument();
            }
            catch (TaskCanceledException) { }
        await base.OnAfterRenderAsync(firstRender);
    }

    async Task InitializeDocument() {
    /* Surround the code that contains an asynchronous operation with a try-catch block to handle
    the OperationCanceledException. This exception is thrown when an asynchronous operation is canceled. */
        try {
            var columnCount = 4;
            var rowCount = 5;
            richEdit.DocumentAPI.BeginUpdate();
            // Creates a table
            Table myTable = await richEdit.DocumentAPI.Tables.CreateAsync(0, columnCount, rowCount);
            for (int i = rowCount-1; i >=0 ; i--)
                for (int j = columnCount-1; j >=0 ; j--) {
                    var cellPosition = myTable.Rows[i].Cells[j].Interval.Start;
                    await richEdit.DocumentAPI.AddTextAsync(cellPosition, "sample text");
                }
            // Customizes the table
            myTable = await richEdit.DocumentAPI.Tables.GetAsync(0);
            foreach (TableRow row in myTable.Rows)
                foreach (TableCell cell in row.Cells)
                    if (cell.CharacterProperties.Script != CharacterFormattingScript.Normal)
                        await cell.ChangePropertiesAsync(properties => {
                            properties.CharacterProperties.Script = CharacterFormattingScript.Normal;
                        });
            richEdit.DocumentAPI.EndUpdate();
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
    }
}

See Also

ICharacterProperties Interface

ICharacterProperties Members

DevExpress.Blazor.RichEdit Namespace