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

73 views Asked by At

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.

2

There are 2 answers

1
David Ortega On BEST ANSWER

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.

1
Syncrow On

You could create your own custom control and override the OnGotFocus function

public partial class FocusTextBox : TextBox {
    public FocusTextBox() {}

    protected override void OnGotFocus(EventArgs e) {
        // Your code to open the keyboard here

        base.OnGotFocus(e);
    }
}