[英]C# tabindex - generalize (desktop app)
I have a few textboxes. 我有几个文本框。 I'd like to point the user each time to the next textbox, on pressing enter.
我想每次按Enter时都将用户指向下一个文本框。 Textboxes have Tabindex set up correctly.
文本框的Tabindex设置正确。
I got something like: 我得到类似的东西:
private void textBox_Description_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
e.Handled = true;
setFocusOnNextElement(sender);
}
}
How should setFocusOnNextElement look like? setFocusOnNextElement应该是什么样子? If i want to make it general.
如果我想使它通用。 I could parse each control, and find what's next, but I have a feeling that this can be done nicer.
我可以解析每个控件,然后找到下一步,但是我感觉这可以做得更好。
I would not advise constructing the function just as you have it, as it would require that the parameter be an object
. 我不建议像您一样构造函数,因为它将要求参数为
object
。
private static void SetFocusOnNextElement(Control control)
{
Control target = Control.GetNextControl(control, true);
if (target != null) target.Focus();
}
Then invoke it like this: 然后像这样调用它:
SetFocusOnNextElement((Control)sender);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.