private void NewQuestion() { questionCount++; questionStartTime = DateTime.Now; questionValue = ResistorValues.GetRandom(); List <Color> l = new List <Color>(); l.AddRange(ResistorHelper.GetColorFromValue(questionValue, true)); l.Add(Color.Gold); questionAnswer = l.ToArray(); lblValue.Text = ResistorHelper.ValueToExpress(questionValue); }
private void NewQuestion() { questionCount++; questionStartTime = DateTime.Now; questionAnswer = ResistorValues.GetRandom(); List <Color> l = new List <Color>(); l.AddRange(ResistorHelper.GetColorFromValue(questionAnswer, true)); l.Add(Color.Gold); questionValue = l.ToArray(); resistorImage1.UpdateBand(questionValue); txtAnswer.Focus(); }
private void txtAnswer_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { long answer = 0; try { answer = ResistorHelper.ExpressToValue(txtAnswer.Text); } catch { errorProvider1.BlinkRate = 100; errorProvider1.SetError(txtAnswer, "输入有误!"); errorFlag = true; txtAnswer.Text = ""; return; } if (answer == questionAnswer) { errorProvider1.Clear(); lastQuestionCostTime = (DateTime.Now - questionStartTime).Seconds; if (!errorFlag) { correctCount++; } txtAnswer.Text = ""; NewQuestion(); } else { errorProvider1.BlinkRate = 100; errorProvider1.SetError(txtAnswer, "答案错误!"); errorFlag = true; txtAnswer.Text = ""; } } }