简体   繁体   English

更改TextBox专注于更改文本?

[英]Change TextBox focus on text change?

I have been searching for hours and still can't find a solution, so how do I change the input from one text box, to another, after text has been entered. 我一直在搜索数小时,但仍然找不到解决方案,因此在输入文本后,如何将输入从一个文本框更改为另一个文本框。 Much like a 'passcode' system, so that the user only has to enter 4 numbers and then it will move onto something else. 非常类似于“密码”系统,因此用户只需输入4个数字,然后它将移至其他内容。

This is my failed attempt so far: 到目前为止,这是我失败的尝试:

txtPasscode1.BecomeFirstResponder();

txtPasscode1.ValueChanged += (object sender, EventArgs e) => 
{
    txtPasscode2.BecomeFirstResponder();
};

All I need it to do, is to switch the focus from one text box to another, when text is entered. 我需要做的就是在输入文本时将焦点从一个文本框切换到另一个文本框。 And of course vice versa when the user hits backspace. 当然,当用户点击退格键时,反之亦然。 Or alternatively, any ideas as to how else this could be achieved would also be appreciated 或者,也可以理解关于如何实现这一目标的任何想法。

why not use the TextBox.TextChanged event? 为什么不使用TextBox.TextChanged事件?

private void TextBox1_TextChanged(object sender, EventArgs e)
    {
        if (TextBox1.Text.Trim().Length == 4)
        {
            TextBox2.Focus();
        }
    }

This is how I managed to fix the problem, for anyone who comes across this in the future: 对于以后遇到此问题的任何人,这就是我设法解决该问题的方法:

NSNotoficationCenter.DefaultCenter.AddObxerver(UITextField.TextFieldTextDidChangeNotification, (notification) => 
{
    //Do whatever needs to be done when the text is changed here
    if (txtFirstInput.IsFirstResponder)
    {
        txtSecondInput.BecomeFirstResponder();
    }
};

This is where I found a solution 这是我找到解决方案的地方

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM