You are on page 1of 4

1

CURSO PROFISSIONAL TCNICO


2013/2014

DE INFORMTICA DE

GESTO

LINGUAGENS DE PROGRAMAO 11 ANO


Ficha n1 Exerccios de Reviso

Cdigo (C#)
using
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Threading.Tasks;
System.Windows.Forms;

namespace Exer_Revisao_01
{
public partial class Form1 : Form
{
double n1, n2, n3, media, max, min;
public Form1()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
//Boto Fechar

Pgina 1 de 4

CURSO PROFISSIONAL TCNICO


2013/2014

DE INFORMTICA DE

GESTO

if (MessageBox.Show("Sair da Aplicao?", "Sair",


MessageBoxButtons.YesNo, MessageBoxIcon.Question)
== DialogResult.Yes)
{
//Application.Exit();
this.Close();
}

//validar a introducao de apenas numeros nas TextBox


// So permite escrever numeros e limpar com tecla backspace
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
//Se a tecla digitada no for nmero e nem backspace
if (!char.IsDigit(e.KeyChar) && e.KeyChar != 08)
{
//Atribui True no Handled para cancelar o evento
e.Handled = true;
}
}
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
//Se a tecla digitada no for nmero e nem backspace
if (!char.IsDigit(e.KeyChar) && e.KeyChar != 08)
{
//Atribui True no Handled para cancelar o evento
e.Handled = true;
}
}
private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
{
//Se a tecla digitada no for nmero e nem backspace
if (!char.IsDigit(e.KeyChar) && e.KeyChar != 08)
{
//Atribui True no Handled para cancelar o evento
e.Handled = true;
}
}
private void button1_Click(object sender, EventArgs e)
{
if ((textBox1.Text != "") && (textBox2.Text != "") && (textBox3.Text != ""))
{
n1 = double.Parse(textBox1.Text);
n2 = double.Parse(textBox2.Text);
n3 = double.Parse(textBox3.Text);
}
else
{
MessageBox.Show("Preencha todos os Valores!", "Valores em Falta");
return;
}
//Calcular Media
media = (n1 + n2 + n3) / 3;

Pgina 2 de 4

CURSO PROFISSIONAL TCNICO


2013/2014

DE INFORMTICA DE

GESTO

label7.Text = media.ToString();
//Calcular Mximo
if (n1 > n2)
if (n1 > n3)
max = n1;
else
max = n3;
else
if (n2 > n3)
max = n2;
else
max = n3;
label8.Text = max.ToString();
//Calcular Mnimo
if (n1 < n2)
if (n1 < n3)
min = n1;
else
min = n3;
else
if (n2 < n3)
min = n2;
else
min = n3;
label9.Text = min.ToString();

}
private void button2_Click(object sender, EventArgs e)
{
//Limpar campos
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
label7.Text = "";
label8.Text = "";
label9.Text = "";
}
// Validar introducao de numeros entre 0 e 20
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text != "")
if ((double.Parse(textBox1.Text) < 0) || (double.Parse(textBox1.Text) > 20))
{
MessageBox.Show("O numero deve estar entre 0 e 20 valores");
textBox1.Text = "";
textBox1.Focus();
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
if (textBox2.Text != "")

Pgina 3 de 4

CURSO PROFISSIONAL TCNICO


2013/2014

DE INFORMTICA DE

GESTO

if ((double.Parse(textBox2.Text) < 0) || (double.Parse(textBox2.Text) > 20))


{
MessageBox.Show("O numero deve estar entre 0 e 20 valores");
textBox2.Text = "";
textBox2.Focus();
}
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
if (textBox3.Text != "")
if ((double.Parse(textBox3.Text) < 0) || (double.Parse(textBox3.Text) > 20))
{
MessageBox.Show("O numero deve estar entre 0 e 20 valores");
textBox3.Text = "";
textBox3.Focus();
}
}
}
}

Pgina 4 de 4

You might also like