How to check if a checkbox in a form has been selected through another form?

0

I want to check if a checkbox is selected on a form, since I'm working with several forms.

Using the following code does not work:

frmPrincipal f = new frmPrincipal();

 if (f.chkNotificacao.Checked == true)
    {                       
       f.notifyIcon1.ShowBalloonTip(1000, "Notificação",
"Um novo usuário foi cadastrado.", ToolTipIcon.Info);
    }

If I put it this way to test, it works, but it will always leave it as true:

  frmPrincipal f = new frmPrincipal();

         f.chkNotificacao.Checked = true;

         if (f.chkNotificacao.Checked == true)
            {                       
               f.notifyIcon1.ShowBalloonTip(1000, "Notificação", 
"Um novo usuário foi cadastrado.", ToolTipIcon.Info);
            }

Is there any other way to do a checkbox check from another form? Well, I need to do the verification.

If a new user is created, this checkbox is checked to trigger a notification.

    
asked by anonymous 11.06.2016 / 02:57

1 answer

0

I looked in other places to see if I could find the solution, and I found, I'll post the code here to help people with the same problem I had.

I created a method for checking the checkbox to see if it was being selected or not.

Code:

  Form2 frm2 = new Form2();
  public bool IsCheckboxChecked
  {
     get { return frm2.chkNotificacoes.Checked; }
  }

  if(IsCheckBoxChecked.Equals(true)) {
   //funcionou
  }
  else {
  //não funcionou
  }

This is the code I made to be able to do the check and it worked normally.

    
11.06.2016 / 16:49