lundi 16 novembre 2015

Creating an event in a custom class that triggers when a checkbox is checked on the main form (simulation of logic gates)

I want to simulate a XOR-gate for example, by using check boxes or radio buttons as input and outputs. I want to create an event in a custom class that triggers when a input check box is checked or unchecked.

this is the custom class that I created

class TriggeringGates
{
    public delegate void Triggering(TriggeringGates gate, EventArgs e);
    public event Triggering Status;

    bool A, B, X;

    public TriggeringGates()
    {
        A = true;
        B = true;
        X = false;
    }

    public bool InputA
    {
        get { return A; }
        set
        {
            A = value;
             X = (A & !B | B & !A);
             Status(this, new EventArgs());  
        }
    }

    public bool InputB
    {
        get { return B; }
        set
        {
            B = value;
            X = (A & !B | B & !A);
            Status(this, new EventArgs());   
        }
    }

    public bool OutputX
    {
        get { return X; }
        set { }
    }

this is the main form... I have no idea how to link the event to this

public partial class Form1 : Form
{
    TriggeringGates trigger;
    public Form1()
    {
        InitializeComponent();
        trigger = new TriggeringGates();
        trigger.Status += new TriggeringGates.Triggering(trigger_Status);
    }

    void trigger_Status(object gate, EventArgs e)
    {
        trigger.InputA = checkBox1.Checked;
        trigger.InputB = checkBox2.Checked;
        trigger.OutputX = checkBox3.Checked;
    }


    private void checkBox3_CheckedChanged_1(object sender, EventArgs e)
    {


    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }
}




Aucun commentaire:

Enregistrer un commentaire