Пример #1
0
 private void LblLives_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar > 48 && e.KeyChar < 54)//if 1,2,3,4,5 pressed
     {
         LblLives.Enabled    = false;
         StartButton.Enabled = true; //Start button is enabled
         StartButton.Visible = true; //Start button is visible
     }
     else//Number not 1,2,3,4,5
     {
         MessageBox.Show("Please enter Numbers 1 to 5 only", "Error");
         e.Handled = true;
         LblLives.Focus();
     }
 }
Пример #2
0
        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar > 95 && e.KeyChar < 124)
            {
                //only display lowercase letters of the alphabet
            }
            else//entered a number or character that isnt in the alphabet
            {
                MessageBox.Show("Please enter letters only", "Error");
                e.Handled = true;
                TextName.Focus();//Focus on name textbox
            }

            if (e.KeyChar > 12 && e.KeyChar < 14)//Enter key pressed
            {
                MessageBox.Show("Please enter your lives now between 1 and 5");
                TextName.Enabled = false; //deny access to name textbox
                LblLives.Focus();         //Focus on lives textbox
            }
        }
Пример #3
0
 private void CheckLives()
 {
     LblLives.Text = lives.ToString();//Show lives on form
     if (lives == 0)
     {
         //Stop the game and initiate a restart sequence
         left               = false;
         right              = false;
         up                 = false;
         down               = false;
         LblLives.Enabled   = true;
         TmrTire.Enabled    = false;
         TmrVehicle.Enabled = false;
         string            message = "Would you like to play again?";
         string            title   = "Game Over";
         MessageBoxButtons buttons = MessageBoxButtons.YesNo;
         DialogResult      result  = MessageBox.Show(message, title, buttons);
         if (result == DialogResult.Yes)
         {
             LblLives.Focus();
         }
     }
 }