Back to Devexpress

How to: Retrieve the List of Document Fonts using the Visitor-Iterator Pattern

windowsforms-116746-controls-and-libraries-rich-text-editor-examples-automation-how-to-retrieve-the-list-of-document-fonts-using-the-visitor-iterator-pattern.md

latest3.3 KB
Original Source

How to: Retrieve the List of Document Fonts using the Visitor-Iterator Pattern

  • May 27, 2025
  • 3 minutes to read

You can use the DocumentIterator to retrieve all fonts used in the document and display them in the ListBoxControl, as shown below:

Follow the steps below to complete this task:

  1. Declare the DocumentVisitorBase class descendant. The DocumentVisitorBase implements the IDocumentVisitor interface. This interface provides the Visit method overloads for every document element type.

  2. In the main class, declare a new Visitor class’s object.

  3. Create a DocumentIterator class object. Pass true to the Iterator constructor as the visibleTextOnly parameter to skip hidden content.

  4. Call the DocumentIterator.MoveNext method to process each element, and use the IDocumentElement.Accept method to allow the Visitor to access the retrieved entity (returned by the DocumentIterator.Current property). When the iterator reaches the end of the document, the IDocumentElement.Accept method returns false. As a result, the Visitor executes the related Visit method for every iterated element.

  5. Pass the retrieved fonts’ list as the BaseListBoxControl.DataSource property value to display the list the ListBoxControl.

  6. Some elements, such as DocumentTextBox or DocumentCommentElement, can contain other elements. Create a new visitor and iterator instance in the corresponding Visit method to get these entities’ content. Use DocumentTextBox.GetIterator or DocumentCommentElement.GetIterator method to provide a new iterator with access to the element’s content. Pass true as the method’s visibleTextOnly parameter to skip hidden content.

See Also

RichEditControl Document

How to use DocumentIterator to export a rich edit document in a custom document format