Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

174
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda