Answer the question
In order to leave comments, you need to log in
How to pass an array from one form to another?
Created 2 WinForms forms, I want to transfer an array from one form to the second.
To do this, I declared a pointer to an integer in a separate file, in the first form I fill it in, and in the second I want to display it.
The file in which the pointer is declared. Decl.h
#pragma once
#ifndef DECL
#define DECL
int *crit_arr;
#endif
//
#pragma once
#include "Decl.h"
// функция заполнения массива внутри класса MyForm
void get_Crit() {
crit_arr[0] = crit_arr[3] = crit_arr[8] = 1;
crit_arr[1] = Convert::ToInt32(textBox1->Text);
crit_arr[2] = Convert::ToInt32(textBox2->Text);
crit_arr[5] = Convert::ToInt32(textBox3->Text);
crit_arr[3] = 1 / crit_arr[1];
crit_arr[6] = 1 / crit_arr[2];
crit_arr[7] = 1 / crit_arr[5];
}
// Кнопка, по которой открывается вторая форма
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
crit_arr = new int[9];
get_Crit();
CritTable^ F2 = gcnew CritTable(this);
F2->Show();
}
#pragma once
#include "Decl.h" // ругается при наличии именно на этот include
// Конструктор, принимающий первую форму
public:
CritTable(System::Windows::Forms::Form ^ frm)
{
InitializeComponent();
mainform = frm;
}
// функция, которая вывод 1й элемент массива во второй форме.
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
int arr[9];
arr[0] = crit_arr[0];
textBox1->Text = Convert::ToString(arr[0]);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question