Professional Documents
Culture Documents
1
private void btnIF_ELSE_IF_Click(object sender, EventArgs e)
{
int vNota;
vNota = Convert.ToInt32(txtNum.Text);
// < 0, 0-7 Reprovou, 8-9 Exame, 10-16 Aprovado, 17-20 Oral, >0
if (vNota < 0)
txtRes.Text = "Inválido";
else if (vNota <= 7)
txtRes.Text = "Reprovou";
else if (vNota <= 9)
txtRes.Text = "Exame";
else if (vNota <= 16)
txtRes.Text = "Aprovado";
else if (vNota <= 20)
txtRes.Text = "Oral";
else
txtRes.Text = "Inválido";
}
3
//Este evento KeyPress só deixa aceitar números e a tecla backspace.
private void txtNum_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsNumber(e.KeyChar) && !(e.KeyChar == (char)Keys.Back))
{
e.Handled = true;
}
}