123 个问题
我建议您将 fieldTextBox 的 CausesValidation 属性更改为 false,这将禁止验证和验证事件。 我做了一个测试,效果很好。 测试结果: 最好的问候, Daniel Zhang
如果回复有帮助,请点击“接受答案”并点赞。
注意:如果您想接收此线程的相关电子邮件通知,请按照我们文档中的步骤启用电子邮件通知。
您好,在我的WinForms应用程序中,我有这个下面的程序,它有助于在按下回车键时转到下一个文本框,但是我在这里遇到了一个问题。 当我在键入内容后按回车键或没有在第一个文本框中键入任何内容时,它将转到下一个文本框。 但是,如果我不小心输入了某些内容并按退格键删除了第一个文本框内容,并且如果我按回车键,那么它不会移动到下一个文本框,请帮助如何解决此问题。
private void Form1_Shown(object sender, EventArgs e)
{
try
{
foreach (Control control in Controls)
{
if (control is TextBox textBox)
{
textBox.KeyDown += (s, ea) =>
{
if (ea.KeyCode != Keys.Enter) return;
ea.SuppressKeyPress = true;
SelectNextControl(ActiveControl, true, true, true, true);
};
}
else if (control is ComboBox comboBox)
{
comboBox.KeyDown += (s, ea) =>
{
if (ea.KeyCode != Keys.Enter) return;
ea.SuppressKeyPress = true;
SelectNextControl(ActiveControl, true, true, true, true);
};
}
else if (control is DateTimePicker dateTimePicker)
{
dateTimePicker.KeyDown += (s, ea) =>
{
if (ea.KeyCode != Keys.Enter) return;
ea.SuppressKeyPress = true;
SelectNextControl(ActiveControl, true, true, true, true);
};
}
}
}
catch (Exception ex)
{
MessageBox.Show("Enter Failed:" + ex.Message.ToString(), "Enter",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Note:此问题总结整理于: Go to next text box when enter is pressed