Práctica 11. Diseño de una GUI
Código:
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 Practica_11
{
public partial class FrmGUI : Form
{
public FrmGUI()
{
InitializeComponent();
}
private void btnEnviar_Click(object sender, EventArgs e)
{
if (txtNombre.Text == "" || txtEdad.Text == "" || txtOcupacion.Text == "")
{
MessageBox.Show("No dejar espacios vacios \nError al tratar de agragar Registros", "Error al agragar", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else
{
btnLimpiar.Visible = true;
listBox1.Visible = true;
listBox1.Items.Add("Mi nombre es: " + txtNombre.Text
+ "\n Mi edad es: " + txtEdad.Text
+ "\n Mi ocupacion es: " + txtOcupacion.Text);
txtEdad.Text = "";
txtNombre.Text = "";
txtOcupacion.Text = "";
}
}
private void btnLimpiar_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
}
private voideliminarSeleccionadoToolStripMenuItem_Click(object sender,EventArgs e)
{
listBox1.Items.Remove(listBox1.SelectedItem);
}
private void txtNombre_KeyPress(object sender, KeyPressEventArgs e)
{
if (Char.IsLetter(e.KeyChar))
{
e.Handled = false;
}
else if (Char.IsControl(e.KeyChar))
{
e.Handled = false;
}
else if (Char.IsSeparator(e.KeyChar))
{
e.Handled = false;
}
else
{
e.Handled = true;
}
if (e.KeyChar == (char)(Keys.Enter))
{
e.Handled = true;
if (txtNombre.Text == "")
{
MessageBox.Show("No dejar el Campo vacio","Mensaje de advertencias", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
SendKeys.Send("{TAB}");
}
}
}
private void txtEdad_KeyPress(object sender, KeyPressEventArgse)
{
if (Char.IsDigit(e.KeyChar))
{
e.Handled = false;
}
else if (Char.IsControl(e.KeyChar))
{
e.Handled = false;
}
else
{
e.Handled = true;
}
if (e.KeyChar == (char)(Keys.Enter))
{
e.Handled = true;
if (txtEdad.Text == "")
{
MessageBox.Show("No dejar el Campo vacio",
"Mensaje de advertencias",MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
SendKeys.Send("{TAB}");
}
}
}
private void txtOcupacion_KeyPress(object sender,KeyPressEventArgs e)
{
if (e.KeyChar == (char)(Keys.Enter))
{
e.Handled = true;
if (txtOcupacion.Text == "")
{
MessageBox.Show("No dejar el Campo vacio",
"Mensaje de advertencias",MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
btnEnviar.PerformClick();
txtNombre.Text = "";
txtEdad.Text = "";
txtOcupacion.Text = "";
listBox1.Visible = true;
txtNombre.Focus();
}
}
}
private void FrmGUI_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult dialogo = MessageBox.Show("¿decea salir de la aplicacion S/N?",
"Salir de la aplicacion", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (dialogo == DialogResult.OK)
{}
else
{
e.Cancel = true;
}
}
}
}