You are on page 1of 4

Estruturas de Decisão

private void btnIF_Click(object sender, EventArgs e)


{
int vNum;
vNum = Convert.ToInt32(txtNum.Text);

if (vNum > 0) txtRes.Text = "Valor Positivo";


if (vNum < 0) txtRes.Text = "Valor Negativo";
if (vNum == 0) txtRes.Text = "Valor Nulo";
}

private void btnIF_ELSE_Click(object sender, EventArgs e)


{
int vNota;
vNota = Convert.ToInt32(txtNum.Text);

if (vNota < 10)


txtRes.Text = "Reprovado";
else
txtRes.Text = "Aprovado";
}

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";
}

private void btnBlocos_Click(object sender, EventArgs e)


{
int vNota;
vNota = Convert.ToInt32(txtNum.Text);
txtRes.ForeColor = Color.White;

if (vNota < 10)


{
txtRes.Text = "Reprovado";
txtRes.BackColor = Color.Red;
}
else
{
txtRes.Text = "Aprovado";
txtRes.BackColor = Color.Green;
}
}

private void btnOpRelacionais_Click(object sender, EventArgs e)


{
int vNota;
vNota = Convert.ToInt32(txtNum.Text);

//if (vNota < 0)


// txtRes.Text = "Inválida";
//else if (vNota < 10)
// txtRes.Text = "Reprovado";
//else if (vNota <= 20)
// txtRes.Text = "Aprovado";
//else
// txtRes.Text = "Inválida";

if (vNota >= 10 && vNota <= 20)


txtRes.Text = "Aprovado";
else if (vNota >= 0 && vNota < 10)
txtRes.Text = "Reprovado";
2
else
txtRes.Text = "Inválida";

//if (vNota >= 0 && vNota < 10) txtRes.Text = "Reprovado";


//if (vNota >= 10 && vNota <= 20) txtRes.Text = "Aprovado";
//if (vNota < 0 || vNota > 20) txtRes.Text = "Inválida";
}

private void btnSwitch_Click(object sender, EventArgs e)


{
int vNota;
vNota = Convert.ToInt32(txtNum.Text);
switch (vNota)
{
case 1:
txtRes.Text = "Mau";
break;
case 2:
txtRes.Text = "Insuficiente";
break;
case 3:
txtRes.Text = "Suficiente";
break;
case 4:
txtRes.Text = "Bom";
break;
case 5:
txtRes.Text = "Muito bom";
break;
default:
txtRes.Text = "Nota inválida";
break;
}
}

** A PARTIR DAQUI, FUI EU QUE ACRESCENTEI**

//Limpa e desactiva os botões


private void btnLimpar_Click(object sender, EventArgs e)
{
txtNum.Clear();
txtRes.Clear();
txtRes.BackColor = Color.White;
txtNum.Focus();
btnIF.Enabled = false;
btnIF_ELSE.Enabled = false;
btnIF_ELSE_IF.Enabled = false;
btnBlocos.Enabled = false;
btnOpRelacionais.Enabled = false;
btnSwitch.Enabled = false;
}

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;
}
}

private void txtRes_TextChanged(object sender, EventArgs e)


{
txtRes.BackColor = Color.Blue;
txtRes.ForeColor = Color.White;
}
private void btnSair_Click(object sender, EventArgs e)
{
Application.Exit();
}
//Activa os botões ao inserir um número. Os botões foram desactivados nas
//propriedades”
private void txtNum_TextChanged(object sender, EventArgs e)
{
btnIF.Enabled = true;
btnIF_ELSE.Enabled = true;
btnIF_ELSE_IF.Enabled = true;
btnBlocos.Enabled = true;
btnOpRelacionais.Enabled = true;
btnSwitch.Enabled = true;
}

You might also like