domingo, 18 de septiembre de 2016

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;
            }
        }
    }

}

Práctica 10. Cálculo de áreas


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

      private void radioButton1_CheckedChanged(object sender,EventArgs e)
        {
            txt1.Visible = true;
            label1.Text = "Radio:";
            label1.Visible = true;
            txt2.Visible = false;
            label2.Visible = false;
            lb3.Visible = false;
            txt3.Visible = false;
           

        }

      private void radioButton3_CheckedChanged(object sender,EventArgs e)
        {
            label1.Text = "Diagonal mayor:";
            label2.Text = "Diagonal menor:";
            txt1.Visible = true;
            txt2.Visible = true;
            label1.Visible = true;
            label2.Visible = true;
            lb3.Visible = false;
            txt3.Visible = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double r, a;
            if(rbtCirculo.Checked)
            {
             r =Convert.ToDouble(txt1.Text);
             a = (r * r) * 3.1416;
             txtRes.Text = Convert.ToString(a);
             txtRes.Visible = true;
             lbRes.Text = "El area del circulo es:";
             lbRes.Visible = true;
            }
            double rom, rom2, ar, rom3;
            if (rbtTriangulo.Checked)
            {
                rom = Convert.ToDouble(txt1.Text);
                rom2 = Convert.ToDouble(txt2.Text);
                ar = (rom * rom2) / 2;
                txtRes.Text = Convert.ToString(ar);
                txtRes.Visible = true;
                lbRes.Text = "El area del triangulo es:";
                lbRes.Visible = true;

           
            }
            if (rbtRombo.Checked)
            {
                rom = Convert.ToDouble(txt1.Text);
                rom2 = Convert.ToDouble(txt2.Text);
                ar = (rom * rom2) / 2;
                txtRes.Text = Convert.ToString(ar);
                txtRes.Visible = true;
                lbRes.Text = "El area del rombo es:";
                lbRes.Visible = true;
           
            }
            if (rbtTrapecio.Checked)
            {
                rom = Convert.ToDouble(txt1.Text);
                rom2 = Convert.ToDouble(txt2.Text);
                rom3 = Convert.ToDouble(txt3.Text);
                ar = ((rom + rom2) * rom3) / 2;
                txtRes.Text = Convert.ToString(ar);
                txtRes.Visible = true;
                lbRes.Text = "El area del trapecio es:";
                lbRes.Visible = true;
            }
            if (rtnRectangulo.Checked)
            {
                rom = Convert.ToDouble(txt1.Text);
                rom2 = Convert.ToDouble(txt2.Text);
                ar = rom * rom2;
                txtRes.Text = Convert.ToString(ar);
                txtRes.Visible = true;
                lbRes.Text = "El area del rectangulo es:";
                lbRes.Visible = true;
            }
          
        }

       

      private void btnLimpiar_Click(object sender, EventArgs e)
        {  
           
            rtnRectangulo.Checked = false;
            rbtTrapecio.Checked = false;
            rbtRombo.Checked = false;
            rbtTriangulo.Checked = false;
            rbtCirculo.Checked = false;
            txt1.Visible = false;
            label1.Visible = false;
            txt2.Visible = false;
            label2.Visible = false;
            lb3.Visible = false;
            txt3.Visible = false;
            lbRes.Visible = false;
            txtRes.Visible = false;
            txt1.Text = "";
            txt2.Text = "";
            txt3.Text = "";
            txtRes.Text = "";
           
        }

      private void rbtTriangulo_CheckedChanged(object sender,EventArgs e)
        {
            label1.Text = "Altura:";
            label2.Text = "Base:";
            txt1.Visible = true;
            txt2.Visible = true;
            label1.Visible = true;
            label2.Visible = true;
            lb3.Visible = false;
            txt3.Visible = false;
        }

      private void rbtTrapecio_CheckedChanged(object sender, EventArgse)
        {
            label1.Text = "Base mayor:";
            label2.Text = "Base menor:";
            lb3.Text = "Altura:";
            txt1.Visible = true;
            txt2.Visible = true;
            txt3.Visible = true;
            label1.Visible = true;
            label2.Visible = true;
            lb3.Visible = true;
        }

     private void rtnRectangulo_CheckedChanged(object sender,EventArgs e)
        {
            label1.Text = "Base:";
            label2.Text = "Altura:";
            txt1.Visible = true;
            txt2.Visible = true;
            label1.Visible = true;
            label2.Visible = true;
            lb3.Visible = false;
            txt3.Visible = false;
        }

        private void btnSalir_Click(object sender, EventArgs e)
        {
            Close();
        }
    }

}