Está en la página 1de 36

SUMA DE DOS NUMEROS

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 WindowsFormsApplicationTextBox1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int valor1 = int.Parse(textBox1.Text);
int valor2 = int.Parse(textBox2.Text);
int suma = valor1 + valor2;
label4.Text = suma.ToString();
}
}
}
NUMERO DE USUARIO Y CONTRASEÑA
Solicitar que se ingrese una clave. Si se ingresa la cadena "abc123" mostrar un
mensaje de clave correcta en caso contrario mostrar clave incorrecta.Utilizar un
control de tipo TextBox para el ingreso de la clave y una Label para mostrar el
resultado al presionar un botón.

CODIGO
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 WindowsFormsApplicationTextBox2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "abc123")
{
label2.Text = "Clave correcta";
}
else
{
label2.Text = "Clave incorrecta";
}
}
}
}

CONFIGURAR ANCHO Y ALTO


Confeccionar un programa que muestre 3 objetos de la clase RadioButton que
permitan configurar el ancho y alto del Form. Cuando se presione un botón
actualizar el ancho y alto.
CODIGO:

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 WindowsFormsApplicationRadioButton1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
if (radioButton1.Checked == true)
{
Width = 640;
Height = 480;
}
else
{
if (radioButton2.Checked == true)
{
Width = 800;
Height = 600;
}
else
{
if (radioButton3.Checked == true)
{
Width = 1024;
Height = 768;
}
}
}
}
}
}
if (radioButton1.Checked == true)
{
Width = 640;
Height = 480;
}
else
{
if (radioButton2.Checked == true)
{
Width = 800;
Height = 600;
}
else
{
if (radioButton3.Checked == true)
{
Width = 1024;
Height = 768;
}
}
}

MENSAJE
Disponer un control Label que muestre el siguiente mensaje: "Esta de acuerdo
con las normas del servicio?", luego un CheckBox y finalmente un objeto de tipo
Button desactivo Cuando se tilde el CheckBox debemos activar el botón
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 WindowsFormsApplicationCheckBox2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
button1.Enabled = true;
}
else
{
button1.Enabled = false;
}
}
}
}

MUESTRA OBJETOS

Confeccionar un programa que muestre 3 objetos de la clase CheckBox con


etiquetas de tres idiomas. Cuando se presiona un botón mostrar en la barra de
títulos del Form todos los CheckBox seleccionados hasta el momento.

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 WindowsFormsApplicationCheckBox1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
Text = "";
if (checkBox1.Checked == true)
{
Text = Text + "(Inglés)";
}
if (checkBox2.Checked == true)
{
Text = Text + "(Francés)";
}
if (checkBox3.Checked == true)
{
Text = Text + "(Alemán)";
}
}
}
}
CALIFICACIONES
Se tiene un conjunto de calificaciones de un grupo de “n” alumnos, realizar un
algoritmo para calcular la calificación media y la calificación más baja de dicho
grupo.
CODIGO
Private void btncalcular_Click(object sender, EventArgse)
{
//Declaración de variables
Int numalumnos;
Double nota, sumanotas, notabaja, promedio;
if(txtnumero.Text!="")
{
//Entrada de datos
numalumnos =Convert.ToInt32(txtnumero.Text);
//Inicializar las variables
sumanotas = 0.0;
notabaja = 20.0;

for(int i=1;i<=numalumnos;i=i+1)
{
nota
=Convert.ToDouble(Microsoft.VisualBasic.Interaction.InputBox("Ingrese nota
del alumno "+i,"Promedio Notas","16",100,100));
sumanotas = sumanotas + nota;
if(nota<notabaja)
{
notabaja = nota;
}
}
promedio = sumanotas / numalumnos;
//Salida de Información
txtpromedio.Text = Convert.ToString(promedio);
txtnotabaja.Text = Convert.ToString(notabaja);

}
else
{
MessageBox.Show("Ingrese un número válido", "Promedio
Notas",MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void btnnuevo_Click(object sender, EventArgs e)
{
txtnumero.Clear();
txtnotabaja.Clear();
txtpromedio.Clear();

private void btnsalir_Click(object sender, EventArgs e)


{
Close();

}
CAPITAL Y TASA DE INTERES

Crea una aplicación sencilla que dado el capital y la tasa de interés calcule el
interés conseguido y el capital final. La fórmula para el cálculo del interés
es I=(C*t)/100siendo C el capital inicial y r la tasa de interés nominal anual en
tanto por ciento. El capital acumulado será el capital inicial más el interés.

Decimal cap, tp, res;


String formato = "{0:#,###,###,##0.00}";
try
{
cap = Convert.ToDecimal(Capital.Text);
tp = Convert.ToDecimal(TpInterés.Text);
}
catch (FormatException exc)
{
cap = 0; tp = 0;
}

// Cálculos de los resultados


res = Convert.ToDecimal(cap * tp / 100);
InterésPro.Text = String.Format(formato, res);
res += cap;
CapitalAc.Text = String.Format(formato, res);

FACTORIAL DE UN NUMERO

using System;
using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace Factorial_E_Repetitivas
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button2_Click(object sender, EventArgs e)
{
int n, f = 1;
n = int.Parse(textBox1.Text);
for (int i=1; i<= n; i++)
{
f *= i;
textBox2.Text = f.ToString();
}
}
private void button3_Click(object sender, EventArgs e)
{
int n, f = 1, i = 1;
n = int.Parse(textBox1.Text);
while (i <= n)
{
f *= i;
i++;
textBox3.Text = f.ToString();
}
}
private void button4_Click(object sender, EventArgs e)
{
int n, f = 1, i = 1;
n = int.Parse(textBox1.Text);
do
{
f *= i;
i++;
}
while
(i <= n);
textBox4.Text = f.ToString();
}
}

DEVUELVE NUMERO A LETRA

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

namespace numero4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int numero;
string letra
private void textBox1_TextChanged(object sender, EventArgs e)
{
numero = int.Parse(textBox1.Text);
}

private void button2_Click(object sender, EventArgs e)


{
Application.Exit();
}

NUMERO PRIMO

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

namespace numero5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

//Variables
int numeroentrada, i;
bool flag;
string respuesta = "";
//Entrada

private void textBox1_TextChanged(object sender, EventArgs e)


{
numeroentrada = int.Parse(textBox1.Text);
}

// Proceso y Salida

private void button1_Click(object sender, EventArgs e)


{
flag = true;
i = 2;
while (i <= numeroentrada / 2)
{
if (numeroentrada % i == 0)
{
flag = false;
break;
}
i++;
}
if (flag)
respuesta = "ES PRIMO";
else
respuesta = "NO ES PRIMO";

textBox2.Text = respuesta;
}

CUENTA LA CANTIDAD DE CARACTERES

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace numero7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Variables
string texto;
int cantidad;
//Entrada
private void textBox1_TextChanged(object sender, EventArgs e)
{
texto = entrada.Text;
}
ORDENACION POR INTERCAMBIOS

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

namespace numero11
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

//Variables
int tmp, i, j, LI, LS;
//Arreglos
int[] n = new int[4];

private void button2_Click(object sender, EventArgs e)


{
Application.Exit();
}
//Entrada
private void textBox1_TextChanged(object sender, EventArgs e)
{
n[0] = int.Parse(textBox1.Text);
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
n[1] = int.Parse(textBox2.Text);
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
n[2] = int.Parse(textBox3.Text);
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
n[3] = int.Parse(textBox4.Text);
}

RECONOCIMIENTO DE VOZ

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Speech.Recognition; // Para el reconocimiento de voz
namespace Reconocimiento_de_voz_1
{
public partial class Form1 : Form
{

// Inicializamos motor de reconocimiento.


SpeechRecognitionEngine reconocimiento_de_voz = new
SpeechRecognitionEngine();

string palabras;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) //Boton escuchar.
Configuración del reconocimiento
{
//Inicia la escucha con el dispositivo de entrada de audio predeterminado
reconocimiento_de_voz.SetInputToDefaultAudioDevice(); // Usaremos el
microfono predeterminado del sistema
reconocimiento_de_voz.LoadGrammar(new DictationGrammar()); //Carga la
gramatica de Windows
reconocimiento_de_voz.SpeechRecognized += te_escucho; // Controlador de
eventos. Se ejecutara al reconocer
reconocimiento_de_voz.RecognizeAsync(RecognizeMode.Multiple);
//Iniciamos reconocimiento
label1.Text = "Te estoy escuchando cuentame: ";
}
void te_escucho(object sender, SpeechRecognizedEventArgs e)
{
palabras = e.Result.Text; // La variable palabras del tipo string toma las
palabras reconocidas.
textBox1.Text = palabras; // Muestra las palabras reconocidas en el textbox
}
private void button3_Click(object sender, EventArgs e) // Boton detener
escucha
{
reconocimiento_de_voz.RecognizeAsyncStop(); //Detiene la escucha
textBox1.Clear(); //limpia el textbox
}
private void button2_Click(object sender, EventArgs e) // Boton Salir
{
Application.Exit();
}
}
}
TABLA DE MULTIPLICAR
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TablaMultiplicar
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

//Variables
int numero;

private void button2_Click(object sender, EventArgs e)


{
numero = Convert.ToInt32(textBox1.Text);
while (numero <= 0)
{
MessageBox.Show("Superior a 0 por favor");
return;
}
for (int i = 1; i <= numero; i++)
{
textBox2.Text += " "+"\r\n";

for (int j = 1; j <= numero; j++)


{
textBox2.AppendText((i * j).ToString() + "\t");
}
}
}

NUMEROS ROMANOS

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace NumerosRomanos_Forms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int numeroentrada;
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button1_Click(object sender, EventArgs e)
{
int Miles, Centenas, Decenas, Unidades, RestoMiles, RestoCentenas,
RestoDecenas, N;
N = numeroentrada;
Miles = N / 1000;
RestoMiles = N % 1000;
Centenas = RestoMiles / 100;
RestoCentenas = RestoMiles % 100;
Decenas = RestoCentenas / 10;
RestoDecenas = RestoCentenas % 10;
Unidades = RestoDecenas;
switch (Miles)
{
case 1: textBox2.Text += "M"; break;
case 2: textBox2.Text += "MM"; break;
case 3: textBox2.Text += "MMM"; break;
}
switch (Centenas)
{
case 1: textBox2.Text += "C"; break;
case 2: textBox2.Text += "CC"; break;
case 3: textBox2.Text += "CCC"; break;
case 4: textBox2.Text += "CD"; break;
case 5: textBox2.Text += "D"; break;
case 6: textBox2.Text += "DC"; break;
case 7: textBox2.Text += "DCC"; break;
case 8: textBox2.Text += "DCCC"; break;
case 9: textBox2.Text += "CM"; break;
}
MAXIMO COMUN DIVISOR

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

namespace MCD_I_Forms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int numero1, numero2, a, b, resultado;

private void button2_Click(object sender, EventArgs e)


{
Application.Exit();
}
private void button1_Click(object sender, EventArgs e)
{
//Algoritmo de Euclides
//Seleccionamos el mayor y el menor para asignarlos
//a las variables a y b respectivamente
numero1 = int.Parse(textBox1.Text);
numero2 = int.Parse(textBox2.Text);
a = Math.Max(numero1, numero2);
b = Math.Min(numero1, numero2);
do //ciclo para las iteraciones
{
resultado = b; // Guardamos el divisor en el resultado
b = a % b; //Guardamos el resto en el divisor
a = resultado; //El divisor para al dividendo
}
while
(b != 0);
textBox3.Text = resultado.ToString();
}
}
}

MAQUINA DE ESTADOS FINITOS

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace MEF
{

public class Form1 : Form


{
private MainMenu mainMenu1;
private MenuItem menuItem1;
private MenuItem mnuSalir;
private MenuItem menuItem3;
private MenuItem mnuInicio;
private MenuItem mnuParo;
private Timer timer1;
private IContainer components;
// Creamos un objeto para la maquina de estados finitos
private CMaquina maquina = new CMaquina();

// Objetos necesarios
public S_objeto[] ListaObjetos = new S_objeto[10];
public S_objeto MiBateria;

public Form1()
{ InitializeComponent();
Random random = new Random();
// Recorremos todos los objetos
for (int n = 0; n < 10; n++)
{
// Colocamos las coordenadas
ListaObjetos[n].x = random.Next(0, 639);
ListaObjetos[n].y = random.Next(0, 479);
// Lo indicamos activo
ListaObjetos[n].activo = true;
}
// Colocamos la bateria
MiBateria.x = random.Next(0, 639);
MiBateria.y = random.Next(0, 479);
MiBateria.activo = true;
maquina.Inicializa(ref ListaObjetos, MiBateria);
}

protected override void Dispose(bool disposing)


{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
static void Main()
{
Application.Run(new Form1());
}
private void mnuSalir_Click(object sender, System.EventArgs e)
{
// Cerramos la ventana y finalizamos la aplicacion
this.Close();
}
private void mnuInicio_Click(object sender, System.EventArgs e)
{
timer1.Enabled = true;
}
private void mnuParo_Click(object sender, System.EventArgs e)
{
timer1.Enabled = false;
}
private void timer1_Tick(object sender, System.EventArgs e)
{
maquina.Control();
this.Invalidate();
}
private void Form1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
// Creamos la fuente y la brocha para el texto
Font fuente = new Font("Arial", 16);
SolidBrush brocha = new SolidBrush(Color.Black);
// Dibujamos el robot
if (maquina.EstadoM == (int)CMaquina.estados.MUERTO)
e.Graphics.DrawRectangle(Pens.Black, maquina.CoordX - 4,
maquina.CoordY - 4, 20, 20);
else
e.Graphics.DrawRectangle(Pens.Green, maquina.CoordX - 4,
maquina.CoordY - 4, 20, 20);

// Dibujamos los objetos


for (int n = 0; n < 10; n++)
if (ListaObjetos[n].activo == true)
e.Graphics.DrawRectangle(Pens.Indigo, ListaObjetos[n].x - 4,
ListaObjetos[n].y - 4, 20, 20);
// Dibujamos la bateria
e.Graphics.DrawRectangle(Pens.IndianRed, MiBateria.x - 4, MiBateria.y
- 4, 20, 20);

e.Graphics.DrawString("Estado -> " + maquina.EstadoM.ToString(),


fuente, brocha, 10, 10);
}
}
}
FACTORES PRIMOS

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FactoresPrimosNumero_Forms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button1_Click(object sender, EventArgs e)
{
int numero, resi, k;
string cadena = textBox2.Text;
numero = int.Parse(textBox1.Text);
k = 2;
if (!int.TryParse(textBox1.Text, out numero)) numero = -1;
if (numero < 2)
{
MessageBox.Show("Numeros negativos NO. \r\n Superiores a 2 por
favor");
textBox1.Clear();
return;
}
while ((numero != 1))
{
resi = numero % k;
if ((resi == 0))
{
cadena += (k.ToString() + " x ");
textBox2.Text = cadena.Remove(cadena.Length - 2);
numero = numero / k;
}
else
{
k = k + 1;
}
}

PROBABILIDAD POLINOMIAL

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ProbabilidadBinomial_I
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Application.Exit();
}
private static long Factorial(long x)
{
if (x <= 1)
return 1;
else
return x * Factorial(x - 1);
}

private static long Combination(long a, long b)


{
if (a <= 1)
return 1;

return Factorial(a) / (Factorial(b) * Factorial(a - b));


}
private double ProbabilidadBinomial (int ensayos, int aciertos, double
probabilidad)
{
double fallos = 1 - probabilidad;
double c = Combination(ensayos, aciertos);
double px = Math.Pow(probabilidad, aciertos);
double qnx = Math.Pow(fallos, ensayos - aciertos);
return c * px * qnx;
}
DIA DEL AÑO
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OrdinalFecha_Forms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)


{
Application.Exit();
}

private void button1_Click(object sender, EventArgs e)


{
int dia, mes, año;

dia = int.Parse(textBox1.Text);
mes = int.Parse(textBox2.Text);
año = int.Parse(textBox3.Text);

if (fechacorrecta(dia, mes, año) == 1)


MostrarOrdinal(diadelaño(dia, mes, año));
else
MessageBox.Show("Fecha Incorrecta");
}

int bisiesto(int año)


{
if ((año % 4 == 0) && (año % 100 != 0) || (año % 400 == 0))
return 1;
else
return 0;
}
int diasdelmes(int mes, int a)
{
int Numerodias = 0;
switch (mes)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: Numerodias = 31; break;
case 2:
if (bisiesto(a) == 1)
Numerodias = 29;
else
Numerodias = 28;
break;
case 4:
case 6:
case 9:
case 11: Numerodias = 30; break;

}
return Numerodias;
}

TRIANGULO DE PASCAL
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TrianguloPascal_III
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)


{
Application.Exit();
}
//Variables
int numero;

private void button1_Click(object sender, EventArgs e)


{
for (int y = 0; y < numero; y++)
{
int c = 1;
for (int q = 0; q < numero - y; q++)
{
textBox2.Text += " ";
}
for (int x = 0; x <= y; x++)
{
textBox2.AppendText(c.ToString());
textBox2.Text += " " + "\n";
c = c * (y - x) / (x + 1);
}
textBox2.Text += " \r\n";
}
}
PROGRAMAS EN LABVIEW
DISPLAY ANODO Y CATODO
COMPUERTAS LOGICAS AND, OR, NOT Y XOR
SEÑAL ANALOGICA PWM
MEDICION DE UN TERMOMETRO

ENCENDIDO DE FOCOS
FACTORIAL
AREA DE UN CIRCULO

SIMULACION DE UN TANQUE

CUATRO SEMAFOROS

También podría gustarte