How to disable the textchanged event in the load event in Visual Studio C #?

0

I have the following problem: I have a function that is called when the button triggers the textchanged event only when I start the program for the first time it calls the textchanged function in the load event. I want when the program starts the textchanged is not fired though the label text. Form_load code:

private void Form1_Load(object sender, EventArgs e)
    {
        lbl_off.Text = "- Modo Offline, conecte para iniciar a contagem.";
     }

Event code text_changed:

  if (lb_TA.Text == "1")
            {
                turno_para_oee = "3";
                Tubeteira_Oee();
              }

  if (lb_TA.Text == "2")
            {
                turno_para_oee = "1";
                Tubeteira_Oee();
              }

  if (lb_TA.Text == "3")
            {
                turno_para_oee = "2";
                Tubeteira_Oee();
              }

}

    
asked by anonymous 17.08.2018 / 18:06

1 answer

0

There are two ways you can solve it at first.

The first, and simplest, is to set this text in the TextBox on the screen itself, in the text property of the component, not having to do this in the Load event.

The second way is for you to remove the TextChanged event definition from the textBox, and only set this event after you have changed the text, in the Load event:

private void Form1_Load(object sender, EventArgs e)
    {
        lbl_off.Text = "- Modo Offline, conecte para iniciar a contagem.";

        lbl_off.TextChanged += _aqui_seu_evento_onChanged_;
    }
    
17.08.2018 / 18:15