using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace p
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public class Win32
        {
            [DllImport("user32.dll", SetLastError = true)]
            public static extern int LoadKeyboardLayoutA(String pwszKLID, int Flags);
        }
        public void Farsi_Convert()
    { 
       System.PlatformID platForm = Environment.OSVersion.Platform;
       System.String windowsType = platForm.ToString();
       if (windowsType == "Win32NT")
           Win32.LoadKeyboardLayoutA("00000429", 1);
       if (windowsType == "Win32Windows" || windowsType == "Win32s")
           Win32.LoadKeyboardLayoutA("00000401", 1);
    }
        public void English_Convert()
        {
            Win32.LoadKeyboardLayoutA("00000409", 1);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            Farsi_Convert();
            textBox1.Clear();
            textBox1.RightToLeft = RightToLeft.Yes;
            textBox1.Focus();
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            Farsi_Convert();
            textBox1.RightToLeft = RightToLeft.Yes;
            textBox1.Focus();
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            English_Convert();
            textBox1.RightToLeft = RightToLeft.No;
            textBox1.Focus();
        }
    }
}
