Back to Devexpress

How to: Enable RTL Mode for Form's Controls, Strings and Images in a Multiple Culture Application

windowsforms-115871-build-an-application-right-to-left-layout-how-to-enable-rtl-mode-for-forms-controls-strings-and-images-in-a-multiple-culture-application.md

latest4.3 KB
Original Source

How to: Enable RTL Mode for Form's Controls, Strings and Images in a Multiple Culture Application

  • Oct 29, 2020
  • 4 minutes to read

This topic describes how to localize form resources (text and images) and add support for multiple languages, including those that use a right-to-left writing system. It also shows how to use the LayoutControl as a container for controls in RTL-aware forms.

Assume that support for RTL mode is required for the following UI.

This is a form (XtraForm) that contains an XtraTabControl with a single tab page. This tab page contains a LayoutControl where TextEdit and SimpleButton controls reside.

The following image is a form localized into Hebrew. The steps to localize the form are detailed below.

The Windows Forms Localization Mechanism provided by Visual Studio helps you add support for RTL mode and localize form resources (text and images). This mechanism is based on resource files, which are automatically compiled into satellite assemblies that contain culture-specific data. See Globalizing and Localizing Applications on MSDN for more information on this localization mechanism.

How to localize a form and enable RTL mode

Follow the steps listed below to support a right-to-left language in an XtraForm, RibbonForm, or TabForm.

  1. In the Properties window, set the form’s Localizable property to true.

  2. Select the required language from the Language property drop-down.

  3. Set the form’s RightToLeft property to Yes , which enables RTL mode for the form. All child controls inherit this setting by default.

  4. Set the form’s RightToLeftLayout to true to reverse (mirror) the form’s control layout. This option is only in effect if the RightToLeft property is set to Yes.

  5. If there is a control container on the form that does not support automatic control mirroring, you must manually reverse the control layout of within that container.

  6. Set custom localized strings and images for all form controls via the Properties window. These values are automatically saved to the corresponding form-based resource files.

  7. You may also want to localize embedded text of DevExpress controls and components (e.g., text in a GridControl‘s column context menu) into your own language. This mechanism is described in the Localizing WinForms Controls via Satellite Resource Assemblies document.

Once the form is displayed on an operating system that uses your target language (Hebrew), the RTL mode is enabled and the UI is automatically translated. You can check the results by explicitly specifying the UI culture on application startup, as shown in the code snippet below.

csharp
using System.Globalization;
using System.Threading;

Thread.CurrentThread.CurrentCulture = new CultureInfo("he");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("he");
vb
Imports System.Globalization
Imports System.Threading

Thread.CurrentThread.CurrentCulture = New CultureInfo("he")
Thread.CurrentThread.CurrentUICulture = New CultureInfo("he")

See Also

How to: Enable RTL Mode for Non-form-based Interfaces in a Multiple Culture Application