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

Asked

Viewed 267 times

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 that when starting the program the textchanged is not triggered although the text of the label.Code of form_load:

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

}

  • does not have another way to declare this text? in the instance of "lbl_off"

1 answer

0

There are two ways you can solve at first.

The first, and simplest, is to set this text in the Textbox on the screen itself, in the component’s text property, not needing to do this in the Load event.

The second way is to remove the Textchanged event setting from the textbox, and only set that 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_;
    }
  • in case my label that changes in textchanged is not that lbl_off but the lb_ta and I did not set anything for the label lb_ta in the event load

  • That doesn’t solve my problem

  • But the changed event is called when changing lbl_off.Text is not?

  • The changed event is being called in your case because in the screen Load you change the label text. Do what I suggested in the first way, in my reply, and remove from Form_load. Go to the label properties and set the Text you want right there, no need to be in the code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.