Pass data from one form to another class

Asked

Viewed 384 times

2

I have very cute Form1 with very cool button and inside it I have a toggle button on-off. I have another class.Cs and I have a condition in it, but it will only perform if that boot there on Form1 is on. follow on Form1.Cs:

        private void metroToggle1_CheckedChanged(object sender, EventArgs e)
    {
        // caso ligado retorna true ou false algo do tipo
    }

My other class.Cs

    if(form1.botao = true ou retorna 0 ou 1){

             // faz alguma coisa
     }

I hope you have understood my question I’m beginner in c# it seems simple for those who have more experience to me ta osso =/. Please in advance for help.

  • Cesar, your question is confused. How is this class used? the class does not run out of nowhere, or is another form?

  • You are inverting dependencies. The class should be used in the form, not the other way around.

  • Kind in have only the pure form.Cs with only the visual part and the buttons on and off, and created another class separate form, where in fact has the actions or what will be done, but will only be done if there in my form the button is turned on, That’s my other class has to know when my form boot was turned on to perform something. I thought something like pass a variable that returns if there in the form the button was turned on and that other class receive this value from the button.

1 answer

3


Cesar, if I understand, Voce wants when Voce change his checkbox and this is marked he perform an action.

You can do it like this:

private void metroToggle1_CheckedChanged(object sender, EventArgs e)
{
    if (metroToggle1.Checked)
    {
        Classe.Executar();
    }
}

Within your Voce Class will have a method called Run

public static void Executar()
{
    /// faz alguma coisa
}
  • Class method should not be static?

  • That’s exactly what I was talking about, I already got here ,it helped me vlw Alexandre.

  • Yes Willian, I forgot

  • Cesar, if the answer was accepted, Oce can mark the answer as accepted on the left side of the answer. http://answall.com/help/someone-answers

Browser other questions tagged

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