简体   繁体   English

Visual Studio C#键输入无法正常工作

[英]Visual Studio c# Key press enter not working

Hey guys I've been struggling with my code ! 大家好,我一直在努力编写代码! I did some research and I don't understand why my code isn't working... Please help ! 我做了一些研究,但我不明白为什么我的代码无法正常工作...请帮助!

private void CheckEnter(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
        if (e.KeyChar == (char)13)
        {
            Debug.WriteLine("It's working!");
            enterKey = true;
        }
        else
        {
            enterKey = false;
        }
    }

    private void textBox_TextChanged(object sender, TextChangedEventArgs e)
    {
        Debug.WriteLine("The text is changing");

        if (enterKey == true)
        {
            encryptKey = encryptInTextBox.Text;
            Debug.WriteLine("The key is " + encryptKey);
        }
    }

Apparently I can't change 'TextChangedEvenArgs' because of how the text box was created, whenever I change it, it comes with an error. 显然,由于文本框的创建方式,我无法更改“ TextChangedEvenArgs”,每当更改它时,都会出现错误。 So, I decided to do it this way, thanks for the help ! 因此,我决定采用这种方式,谢谢您的帮助!

为什么不直接在文本框KEYPRESS或KEYUP事件中检查ENTER键?

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

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