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

Asked

Viewed 3,215 times

0

I want to check if a checkbox has been selected in a form, because I am working with several forms.

Using the following code, :

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, :

  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 check a checkbox from another form ? Because I need to check it.

If a new user is created it will check whether this checkbox has been selected,to trigger a notification.

1 answer

0


I searched elsewhere to see if I could find the solution,.

I created a method to check 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.

Browser other questions tagged

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