jeudi 1 juillet 2021

how to create a variable and use it later in an if statement windows forms c++

I have tried to create a variable when the user clicks a button then use an if statement inside another button inside another form to identify which button the user pressed earlier, but when I use the if statement inside another button the variable is unidentified, I have also included the other form in the code. my code inside the first form button is

private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
        int category = 1;
        this->Hide();
        MyForm3^ obj1 = gcnew MyForm3();
        obj1->ShowDialog();
    }

in the second form

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
    if (category = 1) {
        MessageBox::Show("testing", "check", MessageBoxButtons::OK, MessageBoxIcon::Hand);
    }
}

it shows this error identifier "category" is undefined

Aucun commentaire:

Enregistrer un commentaire