【发布时间】:2017-10-17 00:28:36
【问题描述】:
当按下第二个键时,我失去了调用函数。我为我的按钮使用了 KeyDown 事件。该 KeyDown 将调用一个检查该按钮的函数。我的问题是检查该按钮后,用户必须按另一个 Enter 键或空格键才能继续下一个数据。
这是我的 radiobutton1 KeyDown 事件
private void btn1_KeyDown(object sender, KeyEventArgs e)
{
btn1.BackColor = Color.Blue;
checkAns(btn1.Text, btn1);
}
这是我的 checkAns 函数,它将检查选定的按钮
private void checkAns (string ansText, RadioButton rdo)
{
var row = dTable.Rows[currentRow];
var ans = row["ANSWER"].ToString();
if (ansText == ans)
{
rdo.BackColor = Color.Green;
correctAdd();
//MessageBox.Show("Correct");
}
else
{
rdo.BackColor = Color.Red;
wrongAdd();
//MessageBox.Show("Wrong. Answer is" + " \n " + ans);
}
nextEnter (------); //Here I'm not sure how to call the another keydown/keypress event or value of the enter key
}
这是我的 nextEnter 函数
private void nextEnter(------) //Also at this part.
{
if (------ == Keys.Enter) //And here.
currentRow++;
currentNo++;
remain--;
nextRow();
}
【问题讨论】:
-
您可以将
KeyEventArgs的KeyCode属性从btn1_KeyDown传递给checkAns,然后再传递给nextEnter。 -
@MetaColon,对不起,我不明白。请纠正我。关键代码(输入),即对象?去检查员?
标签: c# visual-studio function event-handling