Skip to main content

How to: Enable RTL Mode in a Right-to-Left Culture Application

  • 6 minutes to read

This topic shows how to enable Right-to-Left mode in an application that uses a single right-to-left (RTL) culture.

To learn how to support multiple cultures and enable RTL mode for one or more cultures in a single application, see How to: Enable RTL Mode for Form’s Controls, Strings and Images in a Multiple Culture Application and How to: Enable RTL Mode for Non-form-based Interfaces in a Multiple Culture Application.

WindowsFormsSettings Class: Global Settings

The WindowsFormsSettings class exposes static properties that specify various global settings common to all DevExpress WinForms controls, including RTL settings.

We recommend that you enable RTL settings via RightToLeft and RightToLeftLayout properties, but if the application is not localized and primarily uses DevExpress controls, you can also use the WindowsFormsSettings.RightToLeft and WindowsFormsSettings.RightToLeftLayout property to support right-to-left languages. These global settings only affect DevExpress forms and controls, and have priority over the RightToLeft/RightToLeftLayout settings exposed by these forms and controls. Set the WindowsFormsSettings.RightToLeft and WindowsFormsSettings.RightToLeftLayout properties before the main application form is created, as shown in the code snippet below.

using DevExpress.XtraEditors;
static class Program {
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() {
        WindowsFormsSettings.RightToLeft = DevExpress.Utils.DefaultBoolean.True;
        WindowsFormsSettings.RightToLeftLayout = DevExpress.Utils.DefaultBoolean.True;
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }
}

Note

The RTL global settings exposed by the WindowsFormsSettings class are not in effect for standard Forms and controls. If you use standard Forms and controls, enable the corresponding RTL settings individually via the RightToLeft and RightToLeftLayout property of each form or control.

Note

When using global settings of the WindowsFormsSettings class, you cannot support both left-to-right and right-to-left cultures in a single application, since these settings cause all DevExpress controls to be displayed from right-to-left. Use these global settings if the application only supports right-to-left languages.

Note

We strongly do not recommend that you use RTL and non-RTL forms simultaneously. Nevertheless, if your application has RTL and non-RTL forms, do not enable the RTL mode using the global settings. Use the form’s settings instead.

RightToLeft Setting

Right-to-left language support includes the alignment of visual elements from right to left. This feature can be enabled by setting the RightToLeft property to Yes for all forms in your application.

DevExpress control layouts are automatically reversed when RTL mode is enabled. The image below shows a drop-down button rendered in default and RTL mode.

RTL_DropDowButton_English RTL_DropDowButton_Hebrew

You can set the RightToLeft property for a form at design time or in code (prior to the form’s display). The code snippet below shows how to enable the RightToLeft setting on an XtraForm.

public partial class Form1 : DevExpress.XtraEditors.XtraForm {
    public Form1() {
        InitializeComponent();
        this.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
    }
}

Note

All controls have a RightToLeft property. The default value of this property is Inherit, which means it inherits the setting from the parent control (typically, a form). It is not good practice to enable RightToLeft on a specific control while other controls are aligned left-to-right, because it may lead to layout issues. Instead, always enable right-to-left alignment via a form’s RightToLeft or WindowsFormsSettings.RightToLeft property (see below).

RightToLeftLayout Setting

The RightToLeftLayout property also maintains RTL mode.This property is provided by forms (a standard Form, XtraForm, RibbonForm or TabForm), and several standard and DevExpress controls. The RightToLeftLayout setting applies the following:

  • Reverses the location of the form’s standard buttons (Minimize, Maximize and Close), system menu and caption (if the caption was left-aligned).
  • Mirrors the layout of controls on the form.

Note

The RightToLeft property must be set to Yes for the RightToLeftLayout setting to take effect.

Set the RightToLeftLayout property for forms at design time or in code (prior to the form’s display). The code below shows how to enable the RightToLeft and RightToLeftLayout settings for a sample RibbonForm.

public partial class Form1 : DevExpress.XtraBars.Ribbon.RibbonForm {
    public Form1() {
        InitializeComponent();
        this.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
        this.RightToLeftLayout = true;
    }
}

Note

At runtime, avoid changing the RightToLeft or RightToLeftLayout property at runtime for forms that are already displayed.

The figure below illustrates a sample RibbonForm displayed in left-to-right and right-to-left locales. Note that the control layout for the right-to-left locale is mirrored.

WindowsFormsSettings_RightToLeftLayout_False WindowsFormsSettings_RightToLeftLayout_True

Certain control containers provide their own RightToLeftLayout settings that activate visual element and child control layout mirroring. In most cases, you need to enable these settings to properly support RTL mode. If a control container (e.g., a standard Windows Forms Panel) does not provide a RightToLeftLayout setting, manually arrange child controls within this container based on the target culture.

Note

By default, DevExpress container controls automatically mirror the layout of their visual elements and child controls in RTL mode (when the form’s RightToLeft setting is enabled and the RightToLeftLayout setting is not set to False). If a DevExpress control container provides its own RightToLeftLayout property, you can set this property to False to prevent automatic layout mirroring for this container. The following control containers provide their own RightToLeftLayout settings.

In relation to RTL, there are several advantages to using LayoutControl as a control container within a form. The LayoutControl maintains a consistent layout and supports RTL mode. This mode is automatically activated for the LayoutControl when the form’s (or LayoutControl’s) RightToLeft property is set to Yes. The image below shows a sample LayoutControl displayed in different locales.

RTL_LayoutControl_English RTL_LayoutControl_Hebrew

Translate DevExpress Predefined Strings

DevExpress controls and components display many predefined string constants (e.g., text in a GridControl‘s column context menu), which are in English by default . You may want to localize these built-in strings into your own language. This mechanism is described in the Localizing WinForms Controls via Satellite Resource Assemblies document.

The approach described in this topic uses the Localization Service to get satellite resource assemblies. When the assemblies are downloaded, locate a folder whose name matches the abbreviation of the required culture (e.g., he for the Hebrew culture), and copy it into the directory where the application’s executable file is located. No code needs to be written, since the application automatically determines the current culture and loads the appropriate assemblies on startup.

See Also