winform sendkey

Zaug 306 Reputation points
2021-08-14T09:32:48.19+00:00

I'm an app and to spread. We select a button from the application. Secondly, we enter small parts, I cannot connect it to a key. ie "e" is requested to switch, and this e key "o" is reviewed.

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,827 questions
0 comments No comments
{count} vote

Accepted answer
  1. Jack J Jun 24,286 Reputation points Microsoft Vendor
    2021-08-16T08:10:33.497+00:00

    @Zaug , If you want to run the keydown events even if the form is hidden, you could try to use Global keyboard monitoring(Hook) to do it.

    Here is a code example you could refer to.

    using System;  
    using System.Runtime.InteropServices;  
    using System.Windows.Forms;  
      
      class KeyboardHook  
        {  
            public event KeyEventHandler KeyDownEvent;  
            public event KeyPressEventHandler KeyPressEvent;  
            public event KeyEventHandler KeyUpEvent;  
      
            public delegate int HookProc(int nCode, Int32 wParam, IntPtr lParam);  
            static int hKeyboardHook = 0;   
                                           
                                           
            public const int WH_KEYBOARD_LL = 13;     
            HookProc KeyboardHookProcedure;   
      
            [StructLayout(LayoutKind.Sequential)]  
            public class KeyboardHookStruct  
            {  
                public int vkCode;    
                public int scanCode;   
                public int flags;    
                public int time;   
                public int dwExtraInfo;   
            }  
       
            [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]  
            public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);  
      
            [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]  
            public static extern bool UnhookWindowsHookEx(int idHook);  
            [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]  
            public static extern int CallNextHookEx(int idHook, int nCode, Int32 wParam, IntPtr lParam);  
      
      
            [DllImport("kernel32.dll")]  
            static extern int GetCurrentThreadId();  
      
            [DllImport("kernel32.dll")]  
            public static extern IntPtr GetModuleHandle(string name);  
      
            public void Start()  
            {  
      
                if (hKeyboardHook == 0)  
                {  
                    KeyboardHookProcedure = new HookProc(KeyboardHookProc);  
                    hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProcedure, GetModuleHandle(System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName), 0);  
                    
                    if (hKeyboardHook == 0)  
                    {  
                        Stop();  
                        throw new Exception("Failed to install keyboard hook");  
                    }  
                }  
            }  
            public void Stop()  
            {  
                bool retKeyboard = true;  
      
                if (hKeyboardHook != 0)  
                {  
                    retKeyboard = UnhookWindowsHookEx(hKeyboardHook);  
                    hKeyboardHook = 0;  
                }  
      
                if (!(retKeyboard)) throw new Exception("Failed to uninstall keyboard hook!");  
            }  
            [DllImport("user32")]  
            public static extern int ToAscii(int uVirtKey,   
                                             int uScanCode,   
                                             byte[] lpbKeyState,   
                                             byte[] lpwTransKey,   
                                             int fuState);   
      
      
            [DllImport("user32")]  
            public static extern int GetKeyboardState(byte[] pbKeyState);  
      
            [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]  
            private static extern short GetKeyState(int vKey);  
      
            private const int WM_KEYDOWN = 0x100;//KEYDOWN  
            private const int WM_KEYUP = 0x101;//KEYUP  
            private const int WM_SYSKEYDOWN = 0x104;//SYSKEYDOWN  
            private const int WM_SYSKEYUP = 0x105;//SYSKEYUP  
      
            private int KeyboardHookProc(int nCode, Int32 wParam, IntPtr lParam)  
            {  
      
                if ((nCode >= 0) && (KeyDownEvent != null || KeyUpEvent != null || KeyPressEvent != null))  
                {  
                    KeyboardHookStruct MyKeyboardHookStruct = (KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct));  
                    // raise KeyDown  
                    if (KeyDownEvent != null && (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN))  
                    {  
                        Keys keyData = (Keys)MyKeyboardHookStruct.vkCode;  
                        KeyEventArgs e = new KeyEventArgs(keyData);  
                        KeyDownEvent(this, e);  
                    }  
      
      
                    if (KeyPressEvent != null && wParam == WM_KEYDOWN)  
                    {  
                        byte[] keyState = new byte[256];  
                        GetKeyboardState(keyState);  
      
                        byte[] inBuffer = new byte[2];  
                        if (ToAscii(MyKeyboardHookStruct.vkCode, MyKeyboardHookStruct.scanCode, keyState, inBuffer, MyKeyboardHookStruct.flags) == 1)  
                        {  
                            KeyPressEventArgs e = new KeyPressEventArgs((char)inBuffer[0]);  
                            KeyPressEvent(this, e);  
                        }  
                    }  
      
      
                    if (KeyUpEvent != null && (wParam == WM_KEYUP || wParam == WM_SYSKEYUP))  
                    {  
                        Keys keyData = (Keys)MyKeyboardHookStruct.vkCode;  
                        KeyEventArgs e = new KeyEventArgs(keyData);  
                        KeyUpEvent(this, e);  
                    }  
      
                }  
                return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);  
            }  
            ~KeyboardHook()  
            {  
                Stop();  
            }  
        }  
    

    You could use it in the Form_Load event.

    private void Form1_Load(object sender, EventArgs e)  
            {  
                var k_hook = new KeyboardHook();  
                k_hook.KeyDownEvent += new KeyEventHandler(hook_KeyDown);  
                k_hook.Start();  
            }  
            private void hook_KeyDown(object sender, KeyEventArgs e)  
            {  
      
                if (e.KeyValue >= (int)Keys.A &&e.KeyValue<=(int)Keys.Z )  
                {  
                    System.Windows.Forms.MessageBox.Show(e.KeyCode.ToString());  
                }  
            }  
    

    Result:

    123516-result.gif


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


2 additional answers

Sort by: Most helpful
  1. Zaug 306 Reputation points
    2021-08-14T09:37:56.693+00:00

    when want my code file , this my code file

    `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.Diagnostics;

    namespace WinFormsApp1
    {
    public partial class Form1 : Form
    {
    private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
    {
    deger = comboBox2.SelectedItem.ToString();
    }

        public Form1() : base()
        {            
            InitializeComponent();
            this.KeyPreview = true;
            //combobox1
            {
                comboBox1.Items.Add("A");
                comboBox1.Items.Add("B");
                comboBox1.Items.Add("C");
                comboBox1.Items.Add("D");
                comboBox1.Items.Add("E");
                comboBox1.Items.Add("F");
                comboBox1.Items.Add("G");
                comboBox1.Items.Add("H");
                comboBox1.Items.Add("İ");
                comboBox1.Items.Add("J");
                comboBox1.Items.Add("K");
                comboBox1.Items.Add("L");
                comboBox1.Items.Add("M");
                comboBox1.Items.Add("N");
                comboBox1.Items.Add("O");
                comboBox1.Items.Add("P");
                comboBox1.Items.Add("R");
                comboBox1.Items.Add("S");
                comboBox1.Items.Add("T");
                comboBox1.Items.Add("U");
                comboBox1.Items.Add("V");
                comboBox1.Items.Add("W");
                comboBox1.Items.Add("X");
                comboBox1.Items.Add("Y");
                comboBox1.Items.Add("Z");
            }
            //combobox2
            {
                comboBox2.Items.Add("A");
                comboBox2.Items.Add("B");
                comboBox2.Items.Add("C");
                comboBox2.Items.Add("D");
                comboBox2.Items.Add("E");
                comboBox2.Items.Add("F");
                comboBox2.Items.Add("G");
                comboBox2.Items.Add("H");
                comboBox2.Items.Add("İ");
                comboBox2.Items.Add("J");
                comboBox2.Items.Add("K");
                comboBox2.Items.Add("L");
                comboBox2.Items.Add("M");
                comboBox2.Items.Add("N");
                comboBox2.Items.Add("O");
                comboBox2.Items.Add("P");
                comboBox2.Items.Add("R");
                comboBox2.Items.Add("S");
                comboBox2.Items.Add("T");
                comboBox2.Items.Add("U");
                comboBox2.Items.Add("V");
                comboBox2.Items.Add("W");
                comboBox2.Items.Add("X");
                comboBox2.Items.Add("Y");
                comboBox2.Items.Add("Z");
            }
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            secilenharf = comboBox1.SelectedItem.ToString();
            if (secilenharf == "A")
            {
                basilacakharf = "a";
            }
            if (secilenharf == "B")
            {
                basilacakharf = "b";
            }
            if (secilenharf == "C")
            {
                basilacakharf = "c";
            }
            if (secilenharf == "D")
            {
                basilacakharf = "d";
            }
            if (secilenharf == "E")
            {
                basilacakharf = "e";
            }
            if (secilenharf == "F")
            {
                basilacakharf = "f";
            }
            if (secilenharf == "G")
            {
                basilacakharf = "g";
            }
            if (secilenharf == "H")
            {
                basilacakharf = "h";
            }
            if (secilenharf == "İ")
            {
                basilacakharf = "i";
            }
            if (secilenharf == "J")
            {
                basilacakharf = "j";
            }
            if (secilenharf == "K")
            {
                basilacakharf = "k";
            }
            if (secilenharf == "L")
            {
                basilacakharf = "l";
            }
            if (secilenharf == "M")
            {
                basilacakharf = "m";
            }
            if (secilenharf == "N")
            {
                basilacakharf = "n";
            }
            if (secilenharf == "O")
            {
                basilacakharf = "o";
            }
            if (secilenharf == "P")
            {
                basilacakharf = "p";
            }
            if (secilenharf == "Q")
            {
                basilacakharf = "q";
            }
            if (secilenharf == "R")
            {
                basilacakharf = "r";
            }
            if (secilenharf == "S")
            {
                basilacakharf = "s";
            }
            if (secilenharf == "T")
            {
                basilacakharf = "t";
            }
            if (secilenharf == "U")
            {
                basilacakharf = "u";
            }
            if (secilenharf == "V")
            {
                basilacakharf = "v";
            }
            if (secilenharf == "W")
            {
                basilacakharf = "w";
            }
            if (secilenharf == "X")
            {
                basilacakharf = "x";
            }
            if (secilenharf == "Y")
            {
                basilacakharf = "y";
            }
            if (secilenharf == "Z")
            {
                basilacakharf = "z";
            }
        }
        private static void ShowWindow(IntPtr p, int v)
        {
        }
    
    
        //DEĞİŞKENLER
        bool oyunacildi = false;
        string oyunadı;
        string chardeger;
        string basilacakharf;
        string deger;
        string secilenharf = "NULL";
    
        //DEĞİŞKENLER BİTİŞ
    
    
        private void button1_Click(object sender, EventArgs e)
        {            
            OpenFileDialog gamename = new OpenFileDialog();
            gamename.Filter = "exe Dosyaları|*.exe";
            gamename.Title = "Oyun Seçin";
            if (gamename.ShowDialog() == DialogResult.OK)
            {
    
                button2.Visible = true;
                oyunadı = gamename.FileName;
                label1.Text += gamename.SafeFileName;
            }           
        }
    
    
        //oyunu açma---------------------------------------------
        private void button2_Click(object sender,EventArgs e)
        {
            oyunacildi = true;            
            if (basilacakharf == "a")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();           
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                if (chardeger == "A")
                {
                    SendKeys.SendWait("a");
                }
                if (chardeger == "B")
                {
                    SendKeys.SendWait("a");
                }
                if (chardeger == "C")
                {
                    SendKeys.SendWait("a");
                }
                if (chardeger == "D")
                {
                    SendKeys.SendWait("a");
                }
    
            }
            if (basilacakharf == "b")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("b");
            }
            if (basilacakharf == "c")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("c");
            }
            if (basilacakharf == "d")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("d");
            }
            if (basilacakharf == "e")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("e");
            }
            if (basilacakharf == "f")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("f");
            }
            if (basilacakharf == "h")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("h");
            }
            if (basilacakharf == "i")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("i");
            }
            if (basilacakharf == "j")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("j");
            }
            if (basilacakharf == "k")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("k");
            }
            if (basilacakharf == "l")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("l");
            }
            if (basilacakharf == "m")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("m");
            }
            if (basilacakharf == "n")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("n");
            }
            if (basilacakharf == "o")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("o");
            }
            if (basilacakharf == "p")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("p");
            }
            if (basilacakharf == "q")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("q");
            }
            if (basilacakharf == "r")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("r");
            }
            if (basilacakharf == "s")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("s");
            }
            if (basilacakharf == "t")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("t");
            }
            if (basilacakharf == "u")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("u");
            }
            if (basilacakharf == "v")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("v");
            }
            if (basilacakharf == "w")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("w");
            }
            if (basilacakharf == "x")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("x");
            }
            if (basilacakharf == "y")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("y");
            }
            if (basilacakharf == "z")
            {
                Process notepad = new Process();
                notepad.StartInfo.FileName = oyunadı;
                notepad.Start();
                notepad.WaitForInputIdle();
                IntPtr p = notepad.MainWindowHandle;
                ShowWindow(p, 1);
                SendKeys.SendWait("z");
            }
        }
        //oyunu açma bitiş---------------------------------------}
    
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.A)
            {
                if(oyunacildi==true)
                {
                    SendKeys.SendWait("O");
                    chardeger = "A";
                }                
            }
            if (e.KeyCode == Keys.B)
            {
                chardeger = "B";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.C)
            {
                chardeger = "C";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.D)
            {
                chardeger = "D";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.E)
            {
                chardeger = "E";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.F)
            {
                chardeger = "F";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.G)
            {
                chardeger = "G";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.H)
            {
                chardeger = "H";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.I)
            {
                chardeger = "I";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.J)
            {
                chardeger = "J";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.K)
            {
                chardeger = "K";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.L)
            {
                chardeger = "L";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.M)
            {
                chardeger = "M";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.N)
            {
                chardeger = "N";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.O)
            {
                chardeger = "O";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.P)
            {
                chardeger = "P";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.Q)
            {
                chardeger = "Q";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.R)
            {
                chardeger = "R";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.S)
            {
                chardeger = "S";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.T)
            {
                chardeger = "T";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.U)
            {
                chardeger = "U";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.V)
            {
                chardeger = "V";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.W)
            {
                chardeger = "W";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.X)
            {
                chardeger = "X";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.Y)
            {
                chardeger = "Y";
                MessageBox.Show(chardeger);
            }
            if (e.KeyCode == Keys.Z)
            {
                chardeger = "Z";
                MessageBox.Show(chardeger);
            }                 
        }
    }
    

    }


  2. Karen Payne MVP 35,036 Reputation points
    2021-08-15T02:05:12.143+00:00

    Not sure exactly where the problem is so will not attempt to answer, instead suggest some refactoring so it's easier to maintain and for others to assist you.

    namespace WindowsFormsApp1
    {
        public partial class Form1 : Form
        {
            readonly Dictionary<string, string> _dictionary = new Dictionary<string, string>();
            private string basilacakharf;
            public Form1()
            {
                InitializeComponent();
    
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
    
    
                foreach (var c in alphabet)
                {
                    _dictionary.Add(c.ToString(), c.ToString().ToLower());
                }
    
                var source = alphabet.ToList();
                comboBox1.DataSource = source;
                comboBox2.DataSource = new List<char>(source);
    
                comboBox1.SelectedIndexChanged += ComboBox1OnSelectedIndexChanged;
            }
    
    
            private void ComboBox1OnSelectedIndexChanged(object sender, EventArgs e)
            {
                // same needed for second comboBox
                basilacakharf = _dictionary[comboBox1.Text];
                Text = $"comboBox1 {basilacakharf}";
            }
        }
    }