プログラミングに関しては、私は学習が遅いです。申し訳ありません。Silverlight で Windows Phone アプリケーションを実行しています。入力を検証しようとしています。
私が抱えている問題は、不正な入力を検出してメッセージが表示されることですが、キーボードが消えて、入力エラーが残ったまま効果的に続行できることです。では、有効な入力なしに彼らが離れないようにする方法はありますか?
ありがとうございました
bool IsDigitsOnly(string str) {
foreach (char c in str) {
if (c < '0' || c > '9') {
return false;
}
}
return true;
}
protected Boolean noLetters() {
if (!IsDigitsOnly(ReadySecTxtBox.Text)) {
MessageBox.Show("digits only");
ReadySecTxtBox.Focus();
return false;
}
if (!IsDigitsOnly(RoundSecTxtBox.Text)) {
MessageBox.Show("digits only");
return false;
}
if (!IsDigitsOnly(RestSecTxtBox.Text)) {
MessageBox.Show("digits only");
return false;
}
if (!IsDigitsOnly(RelaxSecTxtBox.Text)) {
MessageBox.Show("digits only");
return false;
}
if (!IsDigitsOnly(ReadyMinTxtBox.Text)) {
MessageBox.Show("digits only");
return false;
}
if (!IsDigitsOnly(RoundMinTxtBox.Text)) {
MessageBox.Show("digits only");
return false;
}
if (!IsDigitsOnly(RestMinTxtBox.Text)) {
MessageBox.Show("digits only");
return false;
}
if (!IsDigitsOnly(RelaxMinTxtBox.Text)) {
MessageBox.Show("digits only");
return false;
}
if (!IsDigitsOnly(NoRoundsTxtBox.Text)) {
MessageBox.Show("digits only");
return false;
}
else return true;
}
protected Boolean validInputs(){
if (noLetters()) {
if (int.Parse(ReadySecTxtBox.Text) < 0 || int.Parse(ReadySecTxtBox.Text) > 59) {
MessageBox.Show("seconds must be between 0 and 59");
return false;
}
if (int.Parse(RoundSecTxtBox.Text) < 0 || int.Parse(RoundSecTxtBox.Text) > 59) {
MessageBox.Show("seconds must be between 0 and 59");
return false;
}
if (int.Parse(RestSecTxtBox.Text) < 0 || int.Parse(RestSecTxtBox.Text) > 59) {
MessageBox.Show("seconds must be between 0 and 59");
return false;
}
if (int.Parse(RelaxSecTxtBox.Text) < 0 || int.Parse(RelaxSecTxtBox.Text) > 59) {
MessageBox.Show("seconds must be between 0 and 59");
return false;
}
if (int.Parse(ReadyMinTxtBox.Text) < 0 || int.Parse(ReadyMinTxtBox.Text) > 99) {
MessageBox.Show("minutes must be between 0 and 99");
return false;
}
if (int.Parse(RoundMinTxtBox.Text) < 0 || int.Parse(RoundMinTxtBox.Text) > 99) {
MessageBox.Show("minutes must be between 0 and 99");
return false;
}
if (int.Parse(RestMinTxtBox.Text) < 0 || int.Parse(RestMinTxtBox.Text) > 99) {
MessageBox.Show("minutes must be between 0 and 99");
return false;
}
if (int.Parse(RelaxMinTxtBox.Text) < 0 || int.Parse(RelaxMinTxtBox.Text) > 99) {
MessageBox.Show("minutes must be between 0 and 99");
return false;
}
if (int.Parse(NoRoundsTxtBox.Text) < 1 || int.Parse(NoRoundsTxtBox.Text) > 99) {
MessageBox.Show("number of rounds must be between 1 and 99");
return false;
}
else return true;
}
else return false;
}
protected override void OnManipulationStarted(ManipulationStartedEventArgs e) {
if (validInputs()) {
totalSec = (int.Parse(RoundSecTxtBox.Text) + int.Parse(RestSecTxtBox.Text)) * int.Parse(NoRoundsTxtBox.Text)
+ int.Parse(RelaxSecTxtBox.Text) + int.Parse(ReadySecTxtBox.Text);
totalMin = (int.Parse(RoundMinTxtBox.Text) + int.Parse(RestMinTxtBox.Text)) * int.Parse(NoRoundsTxtBox.Text)
+ int.Parse(RelaxMinTxtBox.Text) + int.Parse(ReadyMinTxtBox.Text);
TotalMinTxtBox.Text = totalMin.ToString("00");
TotalSecTxtBox.Text = totalSec.ToString("00");
}
base.OnManipulationStarted(e);
}