Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Dear friends,
I create a C# Windows application form and I make the form from RightToLift = true. Although, I have a ComboBox on it.

When I run the Form I want the Align Text change from Arabic to English side.

I know there is a code
SendKeys.Send("^+");
that do that I mentioned it, however, the code not changed the Align from Arabic to English Side.

Could anybody help me with that, I appreciate that.

What I have tried:

private void comboBox1_Enter(object sender, EventArgs e)
{
     SendKeys.Send("^+");
}
Posted
Updated 20-Jun-23 23:13pm
Comments
Richard MacCutchan 21-Jun-23 4:31am    
Where is the code that handles that key value?

You can use the MS RightToLeft Property to achieve this as at MainMenu.RightToLeft Property[^]

You can use this when your form loads, which will change the text alignment from the Arabic side to the English side when your form loads -
private void Myform_Load(object sender, EventArgs e)
        {
            // Set the RightToLeft property of the form to No
            this.RightToLeft = RightToLeft.No;

            // Set the text alignment of a TextBox control
            MytextBox.TextAlign = HorizontalAlignment.Left;
        }


If you want to manually trigger the change from Arabic to English side, you can create a method to handle it and call that method when needed -
private void ArabicToEnglishAlignment()
        {
            // Set the RightToLeft property of the form to No
            MyForm.RightToLeft = RightToLeft.No;

            // Set the text alignment of a TextBox control
            MytextBox.TextAlign = HorizontalAlignment.Left;
        }

        // Use in another method
        private void MyOtherMethod()
        {
            // Call the method to change the alignment
            ArabicToEnglishAlignment();
        }


Combining the code, you can use -
using System;
using System.Windows.Forms;

namespace TextAlignmentExample
{
    public partial class MyForm : Form
    {
        public MyForm()
        {
            InitializeComponent();
        }

        private void MyForm_Load(object sender, EventArgs e)
        {
            // Set the RightToLeft property of the form to No
            this.RightToLeft = RightToLeft.No;

            // Set the text alignment of a TextBox control
            MytextBox.TextAlign = HorizontalAlignment.Left;
        }

        private void ArabicToEnglishAlignment()
        {
            // Set the RightToLeft property of the form to No
            this.RightToLeft = RightToLeft.No;

            // Set the text alignment of a TextBox control
            MytextBox.TextAlign = HorizontalAlignment.Left;
        }

        // Use in another method
        private void SomeOtherMethod()
        {
            // Call the method to change the alignment
            ArabicToEnglishAlignment();
        }
    }
}
 
Share this answer
 
v2
Comments
Karam Ibrahim 24-Jun-23 8:08am    
Dear Andre Oosthuizen,

I created an application that display is Arabic not English. it is working with that.
However, thanks I will try that.
Andre Oosthuizen 24-Jun-23 8:19am    
It is a pleasure. I understand that your app is in Arabic, your question was 'How do I change alignment from Arabic to English', hence the answer above.
Karam Ibrahim 25-Jun-23 7:24am    
Dear Andre Oosthuzen,
The problem is solved, however, how I can do it for ComboBox?
I appreciate your helping me.
Every control has it's own RightToLeft property - when you drop a ComboBox on your form, it inherits the RightToLeft status from its container.

But there is nothing stopping you setting MyComboBox.RightToLeft either in the designer or programmatically - it will be honoured.
 
Share this answer
 
v2
Comments
Karam Ibrahim 24-Jun-23 8:07am    
Dear @OriginalGriff
I know that, however, I created an application that display is Arabic not English.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900