TX Words: Right to Left

Text Control supports right to left text rendering for languages such as Arabic or Hebrew. Most often, users working with "RTL languages", also prefer an application view with a right-to-left orientation. This sample shows how to implement a button that restarts the program in the opposite application view.

The source code for this example is contained in the following directories:

  • %USERPROFILE%\Documents\TX Text Control 32.0.NET for WPF\CSharp\TX Words\Right To Left
  • %USERPROFILE%\Documents\TX Text Control 32.0.NET for WPF\VB.NET\TX Words\Right To Left

Using the Sample

To change the application view, click the Right to Left button. It opens a message box where the user can confirm the view change by restarting the program. After the application is restarted, the orientation of the sample is changed to right to left.

Image

The Code Behind

When clicking the Right to Left button, the requested layout will be saved as Settings property value before the application is restarted.

private void RightToLeftFormLayout_Click(object sender, System.EventArgs e) {
        bool bIsRightToLeft = (bool)(sender as RibbonButton).Tag;
        if (SaveDirtyDocumentBeforeReset(bIsRightToLeft)) {
                Properties.Settings.Default.RightToLeft = bIsRightToLeft ? FlowDirection.LeftToRight : FlowDirection.RightToLeft;
                SaveRecentFiles();
                m_bRestartApplication = true;
                Application.Current.Shutdown();
        }
}

private void MainWindow_Closed(object sender, System.EventArgs e) {
        if (m_bRestartApplication) {
                System.Diagnostics.Process.Start(Application.ResourceAssembly.Location);
        }
}
Private Sub RightToLeftFormLayout_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim bIsRightToLeft As Boolean = CBool(TryCast(sender, RibbonButton).Tag)
        If SaveDirtyDocumentBeforeReset(bIsRightToLeft) Then
                My.Settings.Default.RightToLeft = If(bIsRightToLeft, FlowDirection.LeftToRight, FlowDirection.RightToLeft)
                SaveRecentFiles()
                m_bRestartApplication = True
                Call Application.Current.Shutdown()
        End If
End Sub

Private Sub MainWindow_Closed(ByVal sender As Object, ByVal e As EventArgs)
        If m_bRestartApplication Then
                Process.Start(Application.ResourceAssembly.Location)
        End If
End Sub

After that, this layout is loaded when the application is initialized for restart.

public MainWindow() {
        InitializeComponent();
        // Get and set saved application settings.
        LoadRightToLeftSettings();
        LoadRecentFiles();
}
Public Sub New()
        ' Add an unhandled exception handler
        Dim currentDomain As AppDomain = AppDomain.CurrentDomain
        AddHandler currentDomain.UnhandledException, AddressOf CurrentDomain_UnhandledException

        Me.InitializeComponent()

        ' Set some texts
        Me.Title = My.Resources.MainWindow_Caption_Product
        Me.m_rtRibbonTableLayoutTab.ContextualTabGroupHeader = My.Resources.ContextualTabGroup_TableTools
        Me.m_rtRibbonFormulaTab.ContextualTabGroupHeader = My.Resources.ContextualTabGroup_TableTools
        Me.m_rtRibbonFrameLayoutTab.ContextualTabGroupHeader = My.Resources.ContextualTabGroup_FrameTools
        Me.m_ctgTableTools.Header = My.Resources.ContextualTabGroup_TableTools
        Me.m_ctgFrameTools.Header = My.Resources.ContextualTabGroup_FrameTools

        ' Get and set saved application settings.
        LoadRightToLeftSettings()
        LoadRecentFiles()
End Sub

It updates the FlowDirection property value of the application.

private void LoadRightToLeftSettings() {
        this.FlowDirection = Properties.Settings.Default.RightToLeft;
}
Private Sub LoadRightToLeftSettings()
        FlowDirection = My.Settings.Default.RightToLeft
End Sub