Visual Studio c# 按键回车不工作
Visual Studio c# Key press enter not working
大家好,我一直在为我的代码苦苦挣扎!我做了一些研究,但我不明白为什么我的代码不起作用......请帮忙!
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);
}
}
显然我无法更改 'TextChangedEvenArgs' 因为文本框的创建方式,每当我更改它时,都会出现错误。
所以,我决定这样做,谢谢你的帮助!
为什么不直接在文本框的 KEYPRESS 或 KEYUP 事件中检查 ENTER 键?
大家好,我一直在为我的代码苦苦挣扎!我做了一些研究,但我不明白为什么我的代码不起作用......请帮忙!
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);
}
}
显然我无法更改 'TextChangedEvenArgs' 因为文本框的创建方式,每当我更改它时,都会出现错误。 所以,我决定这样做,谢谢你的帮助!
为什么不直接在文本框的 KEYPRESS 或 KEYUP 事件中检查 ENTER 键?