mercredi 11 novembre 2020

Simple state design pattern for a visual studio windows form

I'm moving a button component on the form up and down using if-else clauses at the moment.

public void btnUp_Click(object sender, EventArgs e)
{
        if (lift_status == 0)
        {
            timer1.Start();
        }
}

and

public void btnDown_Click(object sender, EventArgs e)
{
        if (lift_status == 1) 
        { 
            timer2.Start();
        }
}

But for my assignment, I need to move the button using the state design pattern instead and I can't implement it.

Can I override the btn_click event handler? How do I create a context class and link it to the form? How do I link the overridden method to the timer method that I have? I'm all kinds of confused.

Simple code for the context class and an example state class would be fantastic, THANKS!!

Aucun commentaire:

Enregistrer un commentaire