Escolar Documentos
Profissional Documentos
Cultura Documentos
______________________________________________________________________
Programação II
2º ANO
Exercício Formulários
1. Crie uma Aplicação Windows para apresentar a tabuada de um número qualquer.
No formulário adicione os seguintes componentes:
4 Label;
3 TextBox
3 Button;
1 ListBox;
1 ComboBox.
2. Alterar as propriedades dos componentes inseridos no formulário. Após as
alterações o formulário deverá ficar tal como se mostra abaixo.
1
FACULDADE DE ENGENHARIAS
DEPARTAMENTO DE ENSINO E INVESTIGAÇÃO DAS TECNOLOGIAS DE INFORMAÇÃO E COMUNICAÇÃO
______________________________________________________________________
Resolução
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Tabuada
{
public partial class frmTabuada : Form
{
public frmTabuada()
{
InitializeComponent();
}
//Declaração de variáveis
int I, F, Vt, N;
//Inicialização dos dados de entrada
Vt = int.Parse(txtVt.Text);
I = int.Parse(txtInicio.Text);
F = int.Parse(txtFim.Text);
if (comboBox1.SelectedItem.ToString() == "Somar")
{
for (N = I; N <= F; N++)
{
listBox1.Items.Add((Vt + " + " +N + " = " + (Vt + N)).ToString());
}
}
else
if (comboBox1.SelectedItem.ToString() == "Diminuir")
{
for (N = I; N <= F; N++)
{
listBox1.Items.Add((Vt - 1 + N + " - " + Vt + " = " +
(Vt - 1 + N - Vt)).ToString());
}
}
else
if (comboBox1.SelectedItem.ToString() == "Multiplicar")
{
for (N = I; N <= F; N++)
{
listBox1.Items.Add((Vt + " x " + N + " = " + N * Vt).ToString());
}
}
2
FACULDADE DE ENGENHARIAS
DEPARTAMENTO DE ENSINO E INVESTIGAÇÃO DAS TECNOLOGIAS DE INFORMAÇÃO E COMUNICAÇÃO
______________________________________________________________________
else
if (comboBox1.SelectedItem.ToString() == "Dividir")
{
for (N = I; N <= F; N++)
{
listBox1.Items.Add((N*Vt+" ÷ " + Vt+" =
"+N*Vt/Vt).ToString());
}
}
txtVt.Focus();
}
}
}