[ Foro de C# ]

Quiero eliminar los txtbox y los label con un boton.

14-Jun-2016 01:55
Irving morales
1 Respuestas

 


 private void ConsultaRadio_Click(object sender, EventArgs e)
        {
            try
            {
                conexion = "Server=10.17.161.171; User id=irving; Database=radiop; Password=0;";
                con.ConnectionString = conexion;
                con.Open();
                //MessageBox.Show("conectado");

                consulta = "select * from radioportatil where numserie='" + textBox1.Text + "'";

                MySqlCommand comandos = new MySqlCommand();
                comandos.Connection = con;
                comandos.CommandText = consulta;
                MySqlDataReader leer = comandos.ExecuteReader();
                if (leer.Read())
                {
                    //Informacion del radio encontrado y presentacion de sus parametros
                    //Aqui mostramos el label informando que el radio existe
                    Label MyLabel = new System.Windows.Forms.Label();
                    MyLabel.Location = new System.Drawing.Point(624,11);
                    MyLabel.Name = "label2";
                    MyLabel.Text = "Radio Encontrado";
                    Controls.Add(MyLabel);

                    //aqui mostraremos el label "ID" del radio
                    Label MyLabel2 = new System.Windows.Forms.Label();
                    MyLabel2.Location = new System.Drawing.Point(472, 56);
                    MyLabel2.Name = "id";
                    MyLabel2.Size = new System.Drawing.Size(35,13);
                    MyLabel2.Text = "ID";
                    Controls.Add(MyLabel2);
                    TextBox MyTextBox = new System.Windows.Forms.TextBox();
                    MyTextBox.Location = new System.Drawing.Point(513, 53);
                    MyTextBox.Name = "id";
                    MyTextBox.Size = new System.Drawing.Size(41,20);
                    MyTextBox.TabIndex = 0;
                    MyTextBox.Text = leer["id"].ToString();
                    Controls.Add(MyTextBox);
 //Se anexa botones para el cierre de consulta y actualizacion.
                    Button MiBoton = new System.Windows.Forms.Button();
                    MiBoton.Location = new System.Drawing.Point(638,232);
                    MiBoton.Name = "actualizar";
                    MiBoton.Size = new System.Drawing.Size(143,23);
                    MiBoton.TabIndex = 0;
                    MiBoton.Text = "Actualizar";
                    Controls.Add(MiBoton);
                    con.Close();
                     MiBoton.Click += new EventHandler(this.MiBoton_Click);

                }
                else
                {
                    MessageBox.Show("Radio no Encontrado");
                    con.Close();
                }
            }

            catch (MySqlException error)
            {
                MessageBox.Show("error" + Convert.ToString(error));
                con.Close();
            }


Cuento con este código. mi pregunta/ duda es la siguiente.
Quiero eliminar MyLabel, MyLabel2 y Mi TextBox al presionar el "MiBoton". Como haría esto?


12-Jul-2016 13:27
Nacho Cabanes (+84)

¿Eliminar por completo?  ¿No sería más sencillo simplemente ocultarlos (hacer que dejen de estar visibles)?






(No se puede continuar esta discusión porque tiene más de dos meses de antigüedad. Si tienes dudas parecidas, abre un nuevo hilo.)