Final
Práctica 1
Desarrollar la práctica, llevarlo a clase para socializar y realizar otras opciones.
descarga, Acá
Prueba
Llenar una matriz cuadrada de 4,4 con números aleatorios, mostrar la matriz.
Buscar un dato en la matriz, si lo encuentra, mostrar la posición en que se encuentra, además, al encontrarlo, colocar allí un 0 (cero).
Almacenar en un vector de 4 elementos, los datos encontrados, cuando el vector esté lleno, no permitir más búsquedas.
Imprimir el vector.
Vector
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
int i,p = 0;
int[] cedula = { 1, 2, 3, 4, 5, 6 };
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (i=0;i < 6; i++)
{
listBox1.Items.Add(i+" "+cedula[i]+" "+ nombre [i]);
}
}
private void button1_Click(object sender, EventArgs e)
{
int i = 0;
int sw = 0;
int ced = int.Parse(txtced.Text);
while (i < 6 && sw != 1)
{
if (ced == cedula[i])
{
sw = 1;
p = i;
}
i++;
txtced.Text = "";
txtced.Focus();
}
if (sw == 1)
{
MessageBox.Show("Encontrada "+p+" "+ i);
label1.Text = "Ud es el jugador: "+ nombre[p];
else
{
MessageBox.Show("No encontrada");
}
}
}
}
Matriz
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 WindowsFormsApp1
{
public partial class Form1 : Form
{
int x = 3;
int[,] matriz= new int[3, 3];
Random rnd = new Random();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int i, j = 0;
dtgmatriz.ColumnCount = x;
dtgmatriz.RowCount = x;
dtgmatriz2.ColumnCount = x;
dtgmatriz2.RowCount = x;
for (i = 0; i < x; i++)
{
dtgmatriz2.Columns[i].Width = 20;
dtgmatriz2.Rows[i].Height = 20;
}
for (i = 0 ; i < x; i++){
for (j= 0; j < x; j++)
{
int alea = rnd.Next(1,10);
matriz[i, j] = alea;
dtgmatriz.Rows[i].Cells[j].Value = alea;
if ((i + j)% 2 == 0){
dtgmatriz2.Rows[i].Cells[j].Style.BackColor = Color.Black;
}
}
}
}
}
}
Eventos
Programar el evento
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
//condicion para solo
números
if (char.IsDigit(e.KeyChar))
{
e.Handled = false;
}
//para tecla backspace
else if (char.IsControl(e.KeyChar))
{
e.Handled = false;
MessageBox.Show("ELIMINANDO DATO","BORRAR DATO");
}
//verifica que pueda
ingresar solo un punto
else if ((e.KeyChar == '.') &&
(!txtnumero.Text.Contains(".")))
{
e.Handled = false;
}
//si no se cumple nada
de lo anterior entonces que no lo deje pasar
else
{
e.Handled = true;
MessageBox.Show("Solo se permite dato numérico", "validación de
números", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
Evento Solo Letras
//condicion para solo letras
if (char.IsLetter(e.KeyChar))
{
e.Handled = false;
}
//para backspace
else if (char.IsControl(e.KeyChar))
{
e.Handled = false;
}
//para que admita
tecla de espacio
else if (char.IsSeparator(e.KeyChar))
{
e.Handled = false;
}
//si no cumple nada de
lo anterior que no lo deje pasar
else
{
e.Handled = true;
MessageBox.Show("Solo se registran letras", "Validación de
texto",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
if (txtnumero.Text == "")
{
MessageBox.Show("Registre Números");
}
else if (textBox2.Text == "") {
MessageBox.Show("Registre letras");
}
else
{
MessageBox.Show("Registrados");
}
No hay comentarios.:
Publicar un comentario