Back to Devexpress

How to: Mark Text as Hidden and Display Hidden Text in the RichEditControl

windowsforms-119803-controls-and-libraries-rich-text-editor-examples-text-how-to-mark-text-as-hidden-and-display-hidden-text-in-the-rich-edit-control.md

latest2.6 KB
Original Source

How to: Mark Text as Hidden and Display Hidden Text in the RichEditControl

  • Jun 29, 2021

The following example describes how to mark text as hidden and display hidden text in the RichEditControl.

Mark Text as Hidden

  1. Use the Range property to get the range occupied by the target text.

  2. Call the SubDocument.BeginUpdateCharacters method to update the character properties. Pass the retrieved range to the method as a range parameter.

  3. Set the CharacterPropertiesBase.Hidden property to true to hide the text.

  4. Call the SubDocument.EndUpdateCharacters method to finalize the update.

The code sample below hides the third document paragraph.

csharp
DocumentRange hiddenRange = richEditControl1.Document.Paragraphs[2].Range;
CharacterProperties hiddenTextProperties = richEditControl1.Document.BeginUpdateCharacters(hiddenRange);
hiddenTextProperties.Hidden = true;
richEditControl1.Document.EndUpdateCharacters(hiddenTextProperties);
vb
Dim hiddenRange As DocumentRange = richEditControl1.Document.Paragraphs(2).Range
Dim hiddenTextProperties As CharacterProperties = richEditControl1.Document.BeginUpdateCharacters(hiddenRange)
hiddenTextProperties.Hidden = True
richEditControl1.Document.EndUpdateCharacters(hiddenTextProperties)

Display Hidden Text

Set the FormattingMarkVisibilityOptions.HiddenText property to RichEditFormattingMarkVisibility.Visible to display hidden text in the RichEditControl. Access the property using the richEditControl.Options.FormattingMarkVisibility notation.

csharp
richEditControl1.Options.FormattingMarkVisibility.HiddenText = RichEditFormattingMarkVisibility.Visible;
vb
richEditControl1.Options.FormattingMarkVisibility.HiddenText = RichEditFormattingMarkVisibility.Visible

The image below illustrates how the RichEditControl displays hidden text.