Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

178
Vistas
Click Event not fired in User Control when multiple instances are created

I've a user control with 2 labels and two textboxes. When the label is clicked the textbox's visible prop is set to true. Here's the code I've used:

    private void label_Heading_Click(object sender, EventArgs e)
    {
        label_Heading.Visible = false;
        textBox_Heading.Text = label_Heading.Text;
        textBox_Heading.Visible = true;
        textBox_Heading.Focus();
    }

After the textbox lose focus, it's visible prop is set to false and the label is updated with the text. Code:

    private void textBox_Heading_Leave(object sender, EventArgs e)
    {
        textBox_Heading.Visible = false;
        if(textBox_Heading.Text != "")
            label_Heading.Text = textBox_Heading.Text;
        label_Heading.Visible = true;
    }

The code to create user controls on click:

    private void label1_Click(object sender, EventArgs e)
    {
        TaskCard _taskCard = new TaskCard(++TOTAL_ITEM_COUNT, PanelName);
        panel_DeletedItem.Controls.Add(_taskCard);
        panel_DeletedItem.Refresh();
    }

These code work fine when a single user control of this type is added to a panel. But if I add more than one, the code works only for the first user control, but it wont work for the new ones, although the event is fired for every user control. What am I missing here? Please suggest.

If I add a mbox to this code, the mbox is displayed for any control, but the rest of the code won't work, except for the first one.

    private void label_Heading_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Test"); // this will display, but the rest of the code is not executed or changes are not visible, i.e., the teboxes are not displayed even if I click the labels
        label_Heading.Visible = false;
        textBox_Heading.Text = label_Heading.Text;
        textBox_Heading.Visible = true;
        textBox_Heading.Focus();
    }
over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda