[英]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.
我正在使用WCE8和.net紧凑框架3.5。
You could create your own custom control and override the OnGotFocus
function 您可以创建自己的自定义控件并覆盖
OnGotFocus
函数
public partial class FocusTextBox : TextBox {
public FocusTextBox() {}
protected override void OnGotFocus(EventArgs e) {
// Your code to open the keyboard here
base.OnGotFocus(e);
}
}
You can find all the control type textbox in your control and gives them the click event with a foreach, for instance 例如,您可以在控件中找到所有控件类型文本框,并为其提供带有foreach的click事件
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. 这样,每当你关注任何文本框时,它都会打开第二个表单,希望这可以帮到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.