How do I pass the value of a variable? Screen

#pragma once #include "MyForm2.h" #include <time.h> #include <random> namespace Проектсформой { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; /// <summary> /// Summary for MyForm1 /// </summary> public ref class MyForm1 : public System::Windows::Forms::Form { public: MyForm1(void) { InitializeComponent(); // //TODO: Add the constructor code here // } protected: /// <summary> /// Clean up any resources being used. /// </summary> ~MyForm1() { if (components) { delete components; } } private: System::Windows::Forms::PictureBox^ pictureBox3; private: System::Windows::Forms::PictureBox^ pictureBox1; private: System::Windows::Forms::PictureBox^ pictureBox4; private: System::Windows::Forms::PictureBox^ pictureBox5; private: System::Windows::Forms::ComboBox^ comboBox1; private: System::Windows::Forms::PictureBox^ pictureBox2; private: System::Windows::Forms::ComboBox^ comboBox2; private: System::Windows::Forms::ComboBox^ comboBox3; private: System::Windows::Forms::ComboBox^ comboBox4; private: System::Windows::Forms::PictureBox^ pictureBox6; private: System::Windows::Forms::Label^ label1; private: System::Windows::Forms::PictureBox^ pictureBox7; private: System::Windows::Forms::PictureBox^ pictureBox8; private: System::Windows::Forms::PictureBox^ pictureBox9; private: System::Windows::Forms::PictureBox^ pictureBox10; protected: private: /// <summary> /// Required designer variable. /// </summary> System::ComponentModel::Container ^components; #pragma region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> void InitializeComponent(void) { System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(MyForm1::typeid)); this->pictureBox3 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox4 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox5 = (gcnew System::Windows::Forms::PictureBox()); this->comboBox1 = (gcnew System::Windows::Forms::ComboBox()); this->pictureBox2 = (gcnew System::Windows::Forms::PictureBox()); this->comboBox2 = (gcnew System::Windows::Forms::ComboBox()); this->comboBox3 = (gcnew System::Windows::Forms::ComboBox()); this->comboBox4 = (gcnew System::Windows::Forms::ComboBox()); this->pictureBox6 = (gcnew System::Windows::Forms::PictureBox()); this->label1 = (gcnew System::Windows::Forms::Label()); this->pictureBox7 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox8 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox9 = (gcnew System::Windows::Forms::PictureBox()); this->pictureBox10 = (gcnew System::Windows::Forms::PictureBox()); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox3))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox4))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox5))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox2))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox6))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox7))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox8))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox9))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox10))->BeginInit(); this->SuspendLayout(); // // pictureBox3 // this->pictureBox3->BackColor = System::Drawing::SystemColors::ButtonHighlight; resources->ApplyResources(this->pictureBox3, L"pictureBox3"); this->pictureBox3->Cursor = System::Windows::Forms::Cursors::Hand; this->pictureBox3->Name = L"pictureBox3"; this->pictureBox3->TabStop = false; this->pictureBox3->Click += gcnew System::EventHandler(this, &MyForm1::pictureBox3_Click); // // pictureBox1 // this->pictureBox1->BackColor = System::Drawing::SystemColors::ButtonHighlight; resources->ApplyResources(this->pictureBox1, L"pictureBox1"); this->pictureBox1->Name = L"pictureBox1"; this->pictureBox1->TabStop = false; // // pictureBox4 // this->pictureBox4->BackColor = System::Drawing::SystemColors::ControlLightLight; resources->ApplyResources(this->pictureBox4, L"pictureBox4"); this->pictureBox4->Name = L"pictureBox4"; this->pictureBox4->TabStop = false; // // pictureBox5 // this->pictureBox5->BackColor = System::Drawing::SystemColors::ControlLightLight; resources->ApplyResources(this->pictureBox5, L"pictureBox5"); this->pictureBox5->Name = L"pictureBox5"; this->pictureBox5->TabStop = false; this->pictureBox5->Click += gcnew System::EventHandler(this, &MyForm1::pictureBox5_Click); // // comboBox1 // this->comboBox1->Cursor = System::Windows::Forms::Cursors::Hand; this->comboBox1->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList; this->comboBox1->FormattingEnabled = true; this->comboBox1->Items->AddRange(gcnew cli::array< System::Object^ >(7) {resources->GetString(L"comboBox1.Items"), resources->GetString(L"comboBox1.Items1"), resources->GetString(L"comboBox1.Items2"), resources->GetString(L"comboBox1.Items3"), resources->GetString(L"comboBox1.Items4"), resources->GetString(L"comboBox1.Items5"), resources->GetString(L"comboBox1.Items6")}); resources->ApplyResources(this->comboBox1, L"comboBox1"); this->comboBox1->Name = L"comboBox1"; // // pictureBox2 // resources->ApplyResources(this->pictureBox2, L"pictureBox2"); this->pictureBox2->Cursor = System::Windows::Forms::Cursors::Hand; this->pictureBox2->Name = L"pictureBox2"; this->pictureBox2->TabStop = false; this->pictureBox2->Click += gcnew System::EventHandler(this, &MyForm1::pictureBox2_Click); // // comboBox2 // this->comboBox2->Cursor = System::Windows::Forms::Cursors::Hand; this->comboBox2->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList; this->comboBox2->FormattingEnabled = true; this->comboBox2->Items->AddRange(gcnew cli::array< System::Object^ >(7) {resources->GetString(L"comboBox2.Items"), resources->GetString(L"comboBox2.Items1"), resources->GetString(L"comboBox2.Items2"), resources->GetString(L"comboBox2.Items3"), resources->GetString(L"comboBox2.Items4"), resources->GetString(L"comboBox2.Items5"), resources->GetString(L"comboBox2.Items6")}); resources->ApplyResources(this->comboBox2, L"comboBox2"); this->comboBox2->Name = L"comboBox2"; // // comboBox3 // this->comboBox3->Cursor = System::Windows::Forms::Cursors::Hand; this->comboBox3->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList; this->comboBox3->FormattingEnabled = true; this->comboBox3->Items->AddRange(gcnew cli::array< System::Object^ >(7) {resources->GetString(L"comboBox3.Items"), resources->GetString(L"comboBox3.Items1"), resources->GetString(L"comboBox3.Items2"), resources->GetString(L"comboBox3.Items3"), resources->GetString(L"comboBox3.Items4"), resources->GetString(L"comboBox3.Items5"), resources->GetString(L"comboBox3.Items6")}); resources->ApplyResources(this->comboBox3, L"comboBox3"); this->comboBox3->Name = L"comboBox3"; // // comboBox4 // this->comboBox4->Cursor = System::Windows::Forms::Cursors::Hand; this->comboBox4->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList; this->comboBox4->FormattingEnabled = true; this->comboBox4->Items->AddRange(gcnew cli::array< System::Object^ >(7) {resources->GetString(L"comboBox4.Items"), resources->GetString(L"comboBox4.Items1"), resources->GetString(L"comboBox4.Items2"), resources->GetString(L"comboBox4.Items3"), resources->GetString(L"comboBox4.Items4"), resources->GetString(L"comboBox4.Items5"), resources->GetString(L"comboBox4.Items6")}); resources->ApplyResources(this->comboBox4, L"comboBox4"); this->comboBox4->Name = L"comboBox4"; // // pictureBox6 // resources->ApplyResources(this->pictureBox6, L"pictureBox6"); this->pictureBox6->Name = L"pictureBox6"; this->pictureBox6->TabStop = false; // // label1 // resources->ApplyResources(this->label1, L"label1"); this->label1->Name = L"label1"; // // pictureBox7 // this->pictureBox7->BackColor = System::Drawing::SystemColors::Menu; resources->ApplyResources(this->pictureBox7, L"pictureBox7"); this->pictureBox7->Name = L"pictureBox7"; this->pictureBox7->TabStop = false; // // pictureBox8 // this->pictureBox8->BackColor = System::Drawing::SystemColors::Menu; resources->ApplyResources(this->pictureBox8, L"pictureBox8"); this->pictureBox8->Name = L"pictureBox8"; this->pictureBox8->TabStop = false; // // pictureBox9 // this->pictureBox9->BackColor = System::Drawing::SystemColors::Menu; resources->ApplyResources(this->pictureBox9, L"pictureBox9"); this->pictureBox9->Name = L"pictureBox9"; this->pictureBox9->TabStop = false; // // pictureBox10 // this->pictureBox10->BackColor = System::Drawing::SystemColors::Menu; resources->ApplyResources(this->pictureBox10, L"pictureBox10"); this->pictureBox10->Name = L"pictureBox10"; this->pictureBox10->TabStop = false; // // MyForm1 // resources->ApplyResources(this, L"$this"); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->BackColor = System::Drawing::SystemColors::ControlLightLight; this->ControlBox = false; this->Controls->Add(this->pictureBox10); this->Controls->Add(this->pictureBox9); this->Controls->Add(this->pictureBox8); this->Controls->Add(this->pictureBox7); this->Controls->Add(this->label1); this->Controls->Add(this->pictureBox6); this->Controls->Add(this->comboBox3); this->Controls->Add(this->comboBox4); this->Controls->Add(this->comboBox2); this->Controls->Add(this->pictureBox2); this->Controls->Add(this->comboBox1); this->Controls->Add(this->pictureBox5); this->Controls->Add(this->pictureBox4); this->Controls->Add(this->pictureBox1); this->Controls->Add(this->pictureBox3); this->DoubleBuffered = true; this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle; this->MaximizeBox = false; this->MinimizeBox = false; this->Name = L"MyForm1"; this->Load += gcnew System::EventHandler(this, &MyForm1::MyForm1_Load); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox3))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox4))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox5))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox2))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox6))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox7))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox8))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox9))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox10))->EndInit(); this->ResumeLayout(false); this->PerformLayout(); } #pragma endregion private: System::Void MyForm1_Load(System::Object^ sender, System::EventArgs^ e) { Show(); int mas[4] ; int a; srand(time(NULL)); for (int i=0; i<4 ; i++) { a=rand()%7; mas[i]=a; } } private: System::Void pictureBox3_Click(System::Object^ sender, System::EventArgs^ e) {Close(); } private: System::Void pictureBox5_Click(System::Object^ sender, System::EventArgs^ e) { MyForm2 ^ F2; F2=gcnew MyForm2(); F2->Show(); } private: System::Void pictureBox2_Click(System::Object^ sender, System::EventArgs^ e) { } }; 

}

Here are these pictureBoxes

explain to me how to make, when checking by clicking on the button, the indices from the combo boxes coincide with the numbers from the array

    1 answer 1

    You essentially need to store some state between calls to various class methods (in this case, the load and click event handlers).

    For this, the class fields were created - move the array there.

     // ... private: int mas[4]; // <--- Выносим сюда private: System::Void MyForm1_Load(System::Object^ sender, System::EventArgs^ e) { Show(); int a; srand(time(NULL)); for (int i=0; i<4 ; i++) { a=rand()%7; mas[i]=a; } } // ... private: System::Void pictureBox2_Click(System::Object^ sender, System::EventArgs^ e) { // Обращаемся к mas[i] так же, как и в MyForm1_Load. // ...