C# 使用Esc(27)键C取消数字向上向下的问题#
我有一个带有access数据库的winform应用程序。 该表单有一个numericUpDown来更改值。取消更改的唯一方法是使用取消按钮或按esc键。因为当用户按下enter/a确认按钮或 更改要调用的UpdateCell()函数的单元格:C# 使用Esc(27)键C取消数字向上向下的问题#,c#,winforms,event-handling,keypress,numericupdown,C#,Winforms,Event Handling,Keypress,Numericupdown,我有一个带有access数据库的winform应用程序。 该表单有一个numericUpDown来更改值。取消更改的唯一方法是使用取消按钮或按esc键。因为当用户按下enter/a确认按钮或 更改要调用的UpdateCell()函数的单元格: dtpGridEdit.Validating += (s, e) => { UpdateCell(); }; comboBoxGridEdit.Validating += (s, e) => { UpdateCe
dtpGridEdit.Validating += (s, e) => { UpdateCell(); };
comboBoxGridEdit.Validating += (s, e) => { UpdateCell(); };
textBoxGridEdit.Validating += (s, e) => { UpdateCell(); };
numericUpDown1.Validating += (s, e) => { UpdateCell(); };
//CancelButton:
buttonGridCancel.Click += (s, e) => { CancelCell(); };
textBoxGridEdit.KeyPress += (s, e) =>
{
if (e.KeyChar == (char)13) // enter in update textbox
{
e.Handled = true; // eat the enter in this multilinebox
UpdateCell();
}
if (e.KeyChar == (char)27) // cancel (Escape) in update textbox
{
CancelCell();
}
};
numericUpDown1.KeyPress += (s, e) =>
{
numericUpDown1.Focus();
if (e.KeyChar == (char)13) // enter in update numericUpDown
{
e.Handled = true;
UpdateCell();
}
if (e.KeyChar == (char)27) // cancel (Escape) in update numericUpDown
{
e.Handled = true;
CancelCell();
}
};
等
如果用户使用数字向上向下的箭头,则可以使用。
如果用户使用numericUpDown中的文本框,它将与
取消按钮,但它不与按下esc功能一起工作
在其他情况下,如dataGrid/ComboBox/TextBox,它以任何方式工作。
问题只在于numericupbown中的文本框和esc key.press功能的组合,但我到处都搜索过
我找不到解决方案(我是编程新手)可能esc在默认情况下在numericupdown控件上工作,并且您的esc处理代码没有执行。调试时断点是否会命中numericupdown的KeyPress事件处理程序?这是一件奇怪的事情,当我调试断点时,断点会命中KeyPress事件,因此我的Cancel函数会工作,因此值会变回原来的值。当我停止调试/删除断点时,它停止工作。我刚和一个高级程序员测试过,他不能给我一个解释,那么接下来呢?你的身体状况好吗?CancelCell是否被执行?当我调试/放置断点时,按键工作,因此他执行CancelCell函数并工作。当我停止调试时,它就会停止工作。我想不出原因。