Search code examples
c#formsvisual-studiowce

How can i open a form everytime a textbox is focused?


im developing a keyboard to a touchscreen display, i need to know how can i program a generic code that everytime any textbox is focused, the form(keyboard) opens. I know i could put in the event focus of every single textbox, but i want to do a generic code. Im working with WCE8 and .net compact framework 3.5.


Solution

  • You can find all the control type textbox in your control and gives them the click event with a foreach, for instance

    foreach(Control ctrl in panel1.Controls)
            {
                if(ctrl is TextBox)
                {
                    ctrl.Click += new EventHandler(OpenSecondForm_Click); 
                }
            }
    
    private void OpenSecondForm_Click(object sender, EventArgs e)
        {
            Form2 form = new Form2();
            form.Show();
        }
    

    in this way, every time you focused any textbox,it will open a second form, I hope this can help you.