The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.

How to: Access the Rich Text Editor Controls

  • 5 min to read

This topic describes how to access and customize the following controls in XAF applications with the Office Module:

Platform

Control

Purpose

WinForms

RichEditControl

Used to show Rich Text documents

ASP.NET

ASPxRichEdit

Used to show Rich Text documents

ASP.NET

ASPxUploadControl

Used to upload Rich Text documents on a server

Access the WinForms-Specific Control (RichEditControl)

Follow the steps below to access the RichEditControl and enable the Spell Check function.

  1. Create a custom ViewController in the WinForms module project.
  2. Add the DevExpress.SpellChecker.v19.2.dll and DevExpress.XtraSpellChecker.v19.2.dll assemblies to the project references.
  3. Override the OnActivated method and handle the RichTextServiceController.CustomizeRichEditControl event. In the event handler, create and setup the SpellChecker object and pass this object to the SpellChecker property.
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Office.Win;
using DevExpress.XtraRichEdit;
using DevExpress.XtraSpellChecker;

public partial class WinRichEditController : ViewController {
// ...
    protected override void OnActivated() {
        base.OnActivated();
        RichTextServiceController controller = Frame.GetController<RichTextServiceController>();
        if(controller != null) {
            controller.CustomizeRichEditControl += Controller_CustomizeRichEditControl;
        }
    }
    private void Controller_CustomizeRichEditControl(object sender, CustomizeRichEditEventArgs e) {
        SpellChecker spellChecker = new SpellChecker();
        spellChecker.SetSpellCheckerOptions(e.RichEditControl, new OptionsSpelling());
        spellChecker.SpellCheckMode = SpellCheckMode.AsYouType;
        e.RichEditControl.SpellChecker = spellChecker;
    }
}
Note

The English dictionary is the default for the Spell Checker. Refer to the Dictionaries topic to see how to change the dictionary.

Access ASP.NET-Specific Controls

Access the ASPxRichEdit Control

Follow the steps below to access the ASPxRichEdit control and enable the Spell Check function.

  1. Create a custom ViewController in the ASP.NET module project.
  2. Add the DevExpress.Web.ASPxSpellChecker.v19.2.dll assembly to the project references.
  3. Override the OnActivated method and handle the ASPxRichTextPropertyEditor.ControlCreated event. In the event handler, create and setup the ASPxSpellCheckerOpenOfficeDictionary object and add this object to the Dictionaries collection. Set the Enabled property to true to enable the Spell Checker component.
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Office.Web;
using DevExpress.Web.ASPxRichEdit;
using DevExpress.Web.ASPxSpellChecker;
using System;
using System.Globalization;
// ...
public class WebRichEditController : ViewController<DetailView> {
    protected override void OnActivated() {
        base.OnActivated();
        foreach(ASPxRichTextPropertyEditor editor in View.GetItems<ASPxRichTextPropertyEditor>()) {
            if(editor.ASPxRichEditControl != null) {
                CustomizeRichEditControl(editor.ASPxRichEditControl);
            } else {
                editor.ControlCreated += Editor_ControlCreated;
            }
        }
    }
    private void Editor_ControlCreated(object sender, EventArgs e) {
        ASPxRichEdit richEdit = ((ASPxRichTextPropertyEditor)sender).ASPxRichEditControl;
        CustomizeRichEditControl(richEdit);
    }
    private void CustomizeRichEditControl(ASPxRichEdit richEdit) {
        ASPxSpellCheckerOpenOfficeDictionary dictionary = new ASPxSpellCheckerOpenOfficeDictionary();
        dictionary.GrammarPath = "~/App_Data/Dictionaries/en_US.aff";
        dictionary.DictionaryPath = "~/App_Data/Dictionaries/en_US.dic";
        dictionary.Culture = new CultureInfo("en-US");
        dictionary.CacheKey = "enDic";
        richEdit.Settings.SpellChecker.Dictionaries.Add(dictionary);
        richEdit.Settings.SpellChecker.Enabled = true;
        richEdit.Settings.SpellChecker.SuggestionCount = 4;
    }
    protected override void OnDeactivated() {
        base.OnDeactivated();
        foreach(ASPxRichTextPropertyEditor editor in View.GetItems<ASPxRichTextPropertyEditor>()) {
            editor.ControlCreated -= Editor_ControlCreated;
        }
    }
}

Access the ASPxUploadControl

Follow the steps below to access the ASPxUploadControl and set the maximum size of the file to be uploaded to the server.

  1. Create a custom ViewController in the ASP.NET module project.
  2. In the overridden OnActivated method, handle the ASPxSpreadsheetPropertyEditor.ControlCreated event.
  3. In the event handler, use the MaxFileSize method to specify the maximum size of the file to be uploaded to the server.
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Office.Web;
using DevExpress.Web;
using System;
// ...
public class WebRichEditUploadController : ViewController<DetailView> {
    protected override void OnActivated() {
        base.OnActivated();
        foreach (ASPxRichTextPropertyEditor editor in View.GetItems<ASPxRichTextPropertyEditor>()) {
            if (editor.ASPxUploadControl != null) {
                CustomizeRichEditUploadControl(editor.ASPxUploadControl);
            }
            else {
                editor.ControlCreated += Editor_ControlCreated;
            }
        }
    }
    private void Editor_ControlCreated(object sender, EventArgs e) {
        ASPxUploadControl richEditUploadControl = ((ASPxRichTextPropertyEditor)sender).ASPxUploadControl;
        CustomizeRichEditUploadControl(richEditUploadControl);
    }
    private void CustomizeRichEditUploadControl(ASPxUploadControl uploadControl) {
        uploadControl.ValidationSettings.MaxFileSize = 104857600;
    }
    protected override void OnDeactivated() {
        base.OnDeactivated();
        foreach (ASPxRichTextPropertyEditor editor in View.GetItems<ASPxRichTextPropertyEditor>()) {
            editor.ControlCreated -= Editor_ControlCreated;
        }
    }
}