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.
Asked
Active
Viewed 69 times
1
-
1Please add some code.. – Ankur Tripathi Aug 24 '18 at 12:41
-
the keyboard is working, i just need to know if there is something i can do to open the form everytime a textbox is focused – Rafael Ferronato Aug 24 '18 at 12:45
2 Answers
2
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);
}
}

Syncrow
- 71
- 1
- 4
-
@RafaelFerronato you use the `FocusTextBox` class instead of `TextBox` class! (you can right click into your `InitializeComponent()` method inside your form's constructor and select `Go To Definition`, there, change `System.Windows.Forms.Controls.TextBox` to `{Namespace}.FocusTextBox`) – Ivan García Topete Aug 24 '18 at 15:29
1
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.

David Ortega
- 51
- 5
-
after initialize the form, you can add that code in the constructor after InitializeComponent() or in load event, if you are using winforms or wpf in your keyboard – David Ortega Aug 24 '18 at 15:40