___ ___ erkimt How do I validate a checkbox from a different class in C #? [closed] ______ qstntxt ___

The problem I want to solve is the following:

I have a form where I have a checkBox, and I have another class that is a type of log that I did, the thing is that based on that checkBox is going to execute or not a series of actions by the class of the log, how can I evaluate that checkbox from this class?

    
______ azszpr211579 ___

Since the class does not access the checkbox as a direct control, you are supposed to pass the value of the checkbox to that kind of log.

It is clear that you will define a parameter of type %code% for this task, something like being

%pre%

from the front would be something like

%pre%

As you will see, the check is passed to that class, not the control, so you maintain the separation of responsibilities of each party.

    
___

0

The problem I want to solve is the following:

I have a form where I have a checkBox, and I have another class that is a type of log that I did, the thing is that based on that checkBox is going to execute or not a series of actions by the class of the log, how can I evaluate that checkbox from this class?

    
asked by Jhonatan Vázquez 07.11.2018 в 18:23
source

1 answer

0

Since the class does not access the checkbox as a direct control, you are supposed to pass the value of the checkbox to that kind of log.

It is clear that you will define a parameter of type bool for this task, something like being

public class Log{

   private bool _flag;

   public Log(bool flag){
      _flag = flag;
   }

   public void Write(string mensaje){

        if(_flag){
           //haces algo
        }
   }
}

from the front would be something like

Flag f = new Flag(checkbox1.Checked);
f.Write("mensaje");

As you will see, the check is passed to that class, not the control, so you maintain the separation of responsibilities of each party.

    
answered by 07.11.2018 / 19:08
source