# Right-to-Left UI

> Write Arabic and Hebrew paragraphs with Direction and ChangeDirection, and mirror a Windows Forms app with RightToLeft, RightToLeftLayout and the ribbon.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for Windows Forms > Document Editor > Ribbon and UI > Right-to-Left UI
- **1529 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/right-to-left/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/right-to-left/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/right-to-left/llms-full.txt

---

Applications for Arabic or Hebrew need two things: text that runs from right to left, and an application window that is mirrored, with the ribbon, the scroll bar and the dialog boxes laid out from right to left. TX Text Control .NET for Windows Forms supports both since version 20.0. The first is a formatting attribute of paragraphs, the second a setting of the form and its controls.

### Right-to-Left Text in the Document

Each line of a document can be bidirectional: it can contain parts written from left to right and parts written from right to left. The writing direction of a paragraph decides in which order these parts are arranged. It is the [Direction](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/paragraphformat/direction-property/llms-full.txt) property of the paragraph format, with the values `Direction.LeftToRight`, the default, and `Direction.RightToLeft` of the [Direction](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/direction/enumeration/llms-full.txt) enumeration.

In a right-to-left paragraph, the natural alignment and the default kind of tab stop are right-aligned, tab positions are measured from the right page margin, and the horizontal ruler shows its origin at the right margin.

Users change the direction with two buttons in the **Paragraph** group of the formatting tab, which the ribbon shows as **Home**: the ribbon items `TXITEM_RightToLeft` and `TXITEM_LeftToRight`. The paragraph formatting dialog box offers the setting as well. In code, [Selection.ChangeDirection](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/selection/changedirection-method/llms-full.txt) changes the direction of all selected paragraphs:

```csharp
private void RightToLeftButton_Click(object sender, EventArgs e)
{
    // Mirror the alignment and the tabs of the selected paragraphs, too
    bool changed = textControl1.Selection.ChangeDirection(Direction.RightToLeft);
}
```

The code works as follows:

- `ChangeDirection` returns `true` if at least one paragraph was changed.
- Besides the direction, it toggles the alignment of the paragraphs from left to right or the other way round, and it toggles left and right tab stops. Centered and justified paragraphs keep their alignment.

[InputFormat.RightToLeft](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/inputformat/righttoleft-property/llms-full.txt) reads or sets the direction at the input position, or of the whole selection, as a `bool?`: `null` means the selection contains paragraphs of both directions. It does not mirror the alignment.

Justified Arabic text can be stretched with Kashida lines instead of wider spaces. [ParagraphFormat.Justification](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/paragraphformat/justification-property/llms-full.txt) chooses `Spaces`, the default, `Kashida` or `SpacesAndKashida`. [Character and Paragraph Formatting](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/formatting/llms-full.txt) describes the other paragraph attributes.

### Mirror the Application

Users of right-to-left languages mostly prefer an application whose window is laid out from right to left as well. The controls of TX Text Control support the `RightToLeft` property of Windows Forms. With `RightToLeft.Yes`:

- the `TextControl` shows its vertical scroll bar at the left border and zooms from the top right corner;
- the built-in dialog boxes and context menus have a right-to-left design;
- the `RulerBar` shows a right-to-left ruler;
- the `ButtonBar` and the `StatusBar` arrange their buttons and text parts from right to left.

The following constructor in *Form1.cs* lays out the whole form from right to left, including the ribbon:

```csharp
using System.Windows.Forms;
using TXTextControl;

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        // Mirror the form and every control on it
        RightToLeft = RightToLeft.Yes;
        RightToLeftLayout = true;

        // The ribbon has a layout setting of its own
        if (textControl1.Ribbon != null)
        {
            textControl1.Ribbon.RightToLeftLayout = true;
        }
    }
}
```

The code works as follows:

- `RightToLeft` is a property of every Windows Forms control. Like the TX Words sample, the code sets it on the form, and the controls on the form, including the `TextControl`, follow it.
- `RightToLeftLayout` of the form turns on the mirrored layout of the form itself.
- The ribbon, available through the [Ribbon](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/ribbon-property/llms-full.txt) property, is derived from `System.Windows.Forms.TabControl` and has its own `RightToLeftLayout` property, which the TX Words sample sets together with that of the form.

### The TX Words Sample

The TX Words sample *Right To Left* switches between both layouts. Its **View** tab has a **Right to Left** button in the **Application View** group. Clicking it opens a message box, and when the user confirms, the sample saves the new layout in the application settings and restarts:

![TX Words with the View tab, the Right to Left button in the Application View group and the Change Form Layout message box asking to restart the application.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-winforms/view-tab-right-to-left.86864311.webp)

After the restart, the constructor of the main form reads the saved setting and assigns it to `RightToLeft`, `RightToLeftLayout` and the `RightToLeftLayout` of the ribbon, as in the code above. The sample is installed in *%USERPROFILE%\\Documents\\TX Text Control 34.0.NET for Windows Forms\\CSharp\\TX Words\\Right To Left*.

### Next Steps

- [Localization and Resource Kit](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/localization/llms-full.txt): texts of the user interface in other languages.
- [Built-in Dialog Boxes](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/dialog-boxes/llms-full.txt): the dialog boxes that are mirrored.
- [Rulers and Status Bar](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/rulers-status-bar/llms-full.txt): the bars around the editor.
- [Built-in Ribbon Tabs](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/ribbon/llms-full.txt): the tabs with the direction buttons.

---

## Nearby

- **Previous:** [Localization and Resource Kit](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/localization/llms-full.txt)
- **Next:** [Events](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/events/llms-full.txt)
