Как переносить информацию между формами?
Есть две формы, на первой есть кнопка, по нажатию которой открывается вторая. В ней в несколько textbox вписываются числа. По нажатию кнопки на второй форме, числа, вписанные в textbox, должны передаваться в первую форму, в переменные. Нашел решение посредством создания класса в основной форме, но получаю много ошибок, которые не знаю, как устранить. Мои попытки реализации: MyForm (основная):
#pragma once
#include <stdlib.h>;
#include <windows.h>
#include <iostream>
#include "MyForm1.h"
#include <string>
namespace kursovaya {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace std;
/// <summary>
/// Сводка для MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public: string str;
public:
MyForm(void)
{
InitializeComponent();
str = new string();
str.a = " ";
}
protected:
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
protected:
private: System::Windows::Forms::PictureBox^ pictureBox1;
private: Bitmap^ img1;
private: Bitmap^ img2;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::Label^ label5;
private: System::Windows::Forms::Label^ label6;
private: System::Windows::Forms::Label^ label7;
private: System::Windows::Forms::CheckBox^ checkBox1;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Button^ button3;
private: System::Windows::Forms::Button^ button4;
private: System::Windows::Forms::Label^ label8;
private: System::Windows::Forms::Label^ label9;
private: System::Windows::Forms::Button^ button5;
private: System::Windows::Forms::Button^ button6;
private: System::Windows::Forms::Button^ button7;
private: System::Windows::Forms::Button^ button8;
private: System::Windows::Forms::Button^ button9;
private: System::Windows::Forms::Button^ button10;
private: System::Windows::Forms::Button^ button11;
private: System::Windows::Forms::Label^ label10;
private: System::Windows::Forms::Button^ button12;
private: System::Windows::Forms::OpenFileDialog^ openFileDialog1;
private: System::Windows::Forms::SaveFileDialog^ saveFileDialog1;
private:
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
void InitializeComponent(void)
{
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->label4 = (gcnew System::Windows::Forms::Label());
this->label5 = (gcnew System::Windows::Forms::Label());
this->label6 = (gcnew System::Windows::Forms::Label());
this->label7 = (gcnew System::Windows::Forms::Label());
this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->button3 = (gcnew System::Windows::Forms::Button());
this->button4 = (gcnew System::Windows::Forms::Button());
this->label8 = (gcnew System::Windows::Forms::Label());
this->label9 = (gcnew System::Windows::Forms::Label());
this->button5 = (gcnew System::Windows::Forms::Button());
this->button6 = (gcnew System::Windows::Forms::Button());
this->button7 = (gcnew System::Windows::Forms::Button());
this->button8 = (gcnew System::Windows::Forms::Button());
this->button9 = (gcnew System::Windows::Forms::Button());
this->button10 = (gcnew System::Windows::Forms::Button());
this->button11 = (gcnew System::Windows::Forms::Button());
this->label10 = (gcnew System::Windows::Forms::Label());
this->button12 = (gcnew System::Windows::Forms::Button());
this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
this->saveFileDialog1 = (gcnew System::Windows::Forms::SaveFileDialog());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))-
>BeginInit();
this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->Location = System::Drawing::Point(32, 174);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(798, 476);
this->pictureBox1->TabIndex = 4;
this->pictureBox1->TabStop = false;
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(39, 662);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(126, 13);
this->label1->TabIndex = 5;
this->label1->Text = L"Разимер изображения:";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(437, 662);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(17, 13);
this->label2->TabIndex = 6;
this->label2->Text = L"X:";
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(490, 662);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(17, 13);
this->label3->TabIndex = 7;
this->label3->Text = L"Y:";
//
// label4
//
this->label4->AutoSize = true;
this->label4->Location = System::Drawing::Point(570, 662);
this->label4->Name = L"label4";
this->label4->Size = System::Drawing::Size(18, 13);
this->label4->TabIndex = 8;
this->label4->Text = L"R:";
//
// label5
//
this->label5->AutoSize = true;
this->label5->Location = System::Drawing::Point(641, 662);
this->label5->Name = L"label5";
this->label5->Size = System::Drawing::Size(18, 13);
this->label5->TabIndex = 9;
this->label5->Text = L"G:";
//
// label6
//
this->label6->AutoSize = true;
this->label6->Location = System::Drawing::Point(706, 662);
this->label6->Name = L"label6";
this->label6->Size = System::Drawing::Size(17, 13);
this->label6->TabIndex = 10;
this->label6->Text = L"B:";
//
// label7
//
this->label7->AutoSize = true;
this->label7->Location = System::Drawing::Point(360, 662);
this->label7->Name = L"label7";
this->label7->Size = System::Drawing::Size(54, 13);
this->label7->TabIndex = 11;
this->label7->Text = L"Пиксель:";
//
// checkBox1
//
this->checkBox1->AutoSize = true;
this->checkBox1->Location = System::Drawing::Point(894, 662);
this->checkBox1->Name = L"checkBox1";
this->checkBox1->Size = System::Drawing::Size(254, 17);
this->checkBox1->TabIndex = 12;
this->checkBox1->Text = L"Применить фильтр к половине изображения";
this->checkBox1->UseVisualStyleBackColor = true;
//
// button1
//
this->button1->Location = System::Drawing::Point(42, 36);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(88, 23);
this->button1->TabIndex = 13;
this->button1->Text = L"Открыть";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(42, 66);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(88, 23);
this->button2->TabIndex = 14;
this->button2->Text = L"Сохранить";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click);
//
// button3
//
this->button3->Location = System::Drawing::Point(42, 96);
this->button3->Name = L"button3";
this->button3->Size = System::Drawing::Size(88, 23);
this->button3->TabIndex = 15;
this->button3->Text = L"Восстановить";
this->button3->UseVisualStyleBackColor = true;
this->button3->Click += gcnew System::EventHandler(this, &MyForm::button3_Click);
//
// button4
//
this->button4->Location = System::Drawing::Point(42, 125);
this->button4->Name = L"button4";
this->button4->Size = System::Drawing::Size(88, 23);
this->button4->TabIndex = 16;
this->button4->Text = L"Выход";
this->button4->UseVisualStyleBackColor = true;
this->button4->Click += gcnew System::EventHandler(this, &MyForm::button4_Click);
//
// label8
//
this->label8->AutoSize = true;
this->label8->Location = System::Drawing::Point(42, 13);
this->label8->Name = L"label8";
this->label8->Size = System::Drawing::Size(36, 13);
this->label8->TabIndex = 17;
this->label8->Text = L"Файл";
//
// label9
//
this->label9->AutoSize = true;
this->label9->Location = System::Drawing::Point(152, 13);
this->label9->Name = L"label9";
this->label9->Size = System::Drawing::Size(76, 13);
this->label9->TabIndex = 18;
this->label9->Text = L"Инструменты";
//
// button5
//
this->button5->Location = System::Drawing::Point(155, 29);
this->button5->Name = L"button5";
this->button5->Size = System::Drawing::Size(75, 23);
this->button5->TabIndex = 19;
this->button5->Text = L"Фильтр 1";
this->button5->UseVisualStyleBackColor = true;
this->button5->Click += gcnew System::EventHandler(this, &MyForm::button5_Click);
//
// button6
//
this->button6->Location = System::Drawing::Point(155, 58);
this->button6->Name = L"button6";
this->button6->Size = System::Drawing::Size(75, 23);
this->button6->TabIndex = 20;
this->button6->Text = L"Фильтр 2";
this->button6->UseVisualStyleBackColor = true;
this->button6->Click += gcnew System::EventHandler(this, &MyForm::button6_Click);
//
// button7
//
this->button7->Location = System::Drawing::Point(155, 87);
this->button7->Name = L"button7";
this->button7->Size = System::Drawing::Size(75, 23);
this->button7->TabIndex = 21;
this->button7->Text = L"Фильтр 3";
this->button7->UseVisualStyleBackColor = true;
this->button7->Click += gcnew System::EventHandler(this, &MyForm::button7_Click);
//
// button8
//
this->button8->Location = System::Drawing::Point(155, 116);
this->button8->Name = L"button8";
this->button8->Size = System::Drawing::Size(75, 23);
this->button8->TabIndex = 22;
this->button8->Text = L"Фильтр 4";
this->button8->UseVisualStyleBackColor = true;
this->button8->Click += gcnew System::EventHandler(this, &MyForm::button8_Click);
//
// button9
//
this->button9->Location = System::Drawing::Point(155, 145);
this->button9->Name = L"button9";
this->button9->Size = System::Drawing::Size(75, 23);
this->button9->TabIndex = 23;
this->button9->Text = L"Фильтр 5";
this->button9->UseVisualStyleBackColor = true;
this->button9->Click += gcnew System::EventHandler(this, &MyForm::button9_Click);
//
// button10
//
this->button10->Location = System::Drawing::Point(256, 36);
this->button10->Name = L"button10";
this->button10->Size = System::Drawing::Size(134, 23);
this->button10->TabIndex = 24;
this->button10->Text = L"Увеличить масштаб";
this->button10->UseVisualStyleBackColor = true;
//
// button11
//
this->button11->Location = System::Drawing::Point(256, 66);
this->button11->Name = L"button11";
this->button11->Size = System::Drawing::Size(134, 23);
this->button11->TabIndex = 25;
this->button11->Text = L"Уменьшить масштаб";
this->button11->UseVisualStyleBackColor = true;
//
// label10
//
this->label10->AutoSize = true;
this->label10->Location = System::Drawing::Point(256, 13);
this->label10->Name = L"label10";
this->label10->Size = System::Drawing::Size(26, 13);
this->label10->TabIndex = 26;
this->label10->Text = L"Вид";
//
// button12
//
this->button12->Location = System::Drawing::Point(417, 36);
this->button12->Name = L"button12";
this->button12->Size = System::Drawing::Size(75, 23);
this->button12->TabIndex = 27;
this->button12->Text = L"Справка";
this->button12->UseVisualStyleBackColor = true;
//
// openFileDialog1
//
this->openFileDialog1->FileName = L"openFileDialog1";
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(1218, 695);
this->Controls->Add(this->button12);
this->Controls->Add(this->label10);
this->Controls->Add(this->button11);
this->Controls->Add(this->button10);
this->Controls->Add(this->button9);
this->Controls->Add(this->button8);
this->Controls->Add(this->button7);
this->Controls->Add(this->button6);
this->Controls->Add(this->button5);
this->Controls->Add(this->label9);
this->Controls->Add(this->label8);
this->Controls->Add(this->button4);
this->Controls->Add(this->button3);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->checkBox1);
this->Controls->Add(this->label7);
this->Controls->Add(this->label6);
this->Controls->Add(this->label5);
this->Controls->Add(this->label4);
this->Controls->Add(this->label3);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->pictureBox1);
this->Name = L"MyForm";
this->Text = L"0105_ТасмагамбетовАндрей";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
if (openFileDialog1 -> ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
img1 = gcnew Bitmap(openFileDialog1 -> FileName);
img2 = gcnew Bitmap(openFileDialog1->FileName);
pictureBox1 -> Image = img1;
}
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
if (pictureBox1->Image)
{
pictureBox1->Image = img2;
img1 = img2;
}
else
MessageBox::Show("Ошибка, картинка не загружена");
}
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
exit(0);
}
private: System::Void button6_Click(System::Object^ sender, System::EventArgs^ e) {
if (pictureBox1->Image)
{
int q1;
MyForm^ frm2 = gcnew MyForm(str);
frm2->ShowDialog();
q1 = atoi(str);
}
else
MessageBox::Show("Error, picture missing");
}
}
};
}
MyForm1 (вторая форма):
#pragma once
#include <iostream>
#include <string>
#include "MyForm.h"
namespace kursovaya {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace std;
/// <summary>
/// Сводка для MyForm1
/// </summary>
///
public ref class MyForm1 : public System::Windows::Forms::Form
{
private: string str2; // Делаю указатель
public:
MyForm1(string Astr)
{
InitializeComponent();
str2 = Astr;
}
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
~MyForm1()
{
if (components)
{
delete components;
}
};
private: System::Windows::Forms::Label^ label1;
protected:
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::Label^ label5;
private: System::Windows::Forms::Label^ label6;
private: System::Windows::Forms::Label^ label7;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::TextBox^ textBox3;
private: System::Windows::Forms::TextBox^ textBox4;
private: System::Windows::Forms::TextBox^ textBox5;
private: System::Windows::Forms::TextBox^ textBox6;
private: System::Windows::Forms::Button^ button1;
private:
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
void InitializeComponent(void)
{
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->label4 = (gcnew System::Windows::Forms::Label());
this->label5 = (gcnew System::Windows::Forms::Label());
this->label6 = (gcnew System::Windows::Forms::Label());
this->label7 = (gcnew System::Windows::Forms::Label());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->textBox3 = (gcnew System::Windows::Forms::TextBox());
this->textBox4 = (gcnew System::Windows::Forms::TextBox());
this->textBox5 = (gcnew System::Windows::Forms::TextBox());
this->textBox6 = (gcnew System::Windows::Forms::TextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(38, 24);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(151, 13);
this->label1->TabIndex = 0;
this->label1->Text = L"Введите диапазон q1-q2 для";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(41, 92);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(15, 13);
this->label2->TabIndex = 1;
this->label2->Text = L"R";
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(41, 151);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(15, 13);
this->label3->TabIndex = 2;
this->label3->Text = L"G";
//
// label4
//
this->label4->AutoSize = true;
this->label4->Location = System::Drawing::Point(41, 205);
this->label4->Name = L"label4";
this->label4->Size = System::Drawing::Size(14, 13);
this->label4->TabIndex = 3;
this->label4->Text = L"B";
//
// label5
//
this->label5->AutoSize = true;
this->label5->Location = System::Drawing::Point(41, 252);
this->label5->Name = L"label5";
this->label5->Size = System::Drawing::Size(63, 13);
this->label5->TabIndex = 4;
this->label5->Text = L"от 1 до 255";
//
// label6
//
this->label6->AutoSize = true;
this->label6->Location = System::Drawing::Point(130, 49);
this->label6->Name = L"label6";
this->label6->Size = System::Drawing::Size(19, 13);
this->label6->TabIndex = 6;
this->label6->Text = L"q1";
//
// label7
//
this->label7->AutoSize = true;
this->label7->Location = System::Drawing::Point(404, 49);
this->label7->Name = L"label7";
this->label7->Size = System::Drawing::Size(19, 13);
this->label7->TabIndex = 7;
this->label7->Text = L"q2";
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(112, 92);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(100, 20);
this->textBox1->TabIndex = 8;
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(363, 91);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(100, 20);
this->textBox2->TabIndex = 9;
//
// textBox3
//
this->textBox3->Location = System::Drawing::Point(112, 143);
this->textBox3->Name = L"textBox3";
this->textBox3->Size = System::Drawing::Size(100, 20);
this->textBox3->TabIndex = 10;
//
// textBox4
//
this->textBox4->Location = System::Drawing::Point(363, 143);
this->textBox4->Name = L"textBox4";
this->textBox4->Size = System::Drawing::Size(100, 20);
this->textBox4->TabIndex = 11;
//
// textBox5
//
this->textBox5->Location = System::Drawing::Point(112, 198);
this->textBox5->Name = L"textBox5";
this->textBox5->Size = System::Drawing::Size(100, 20);
this->textBox5->TabIndex = 12;
//
// textBox6
//
this->textBox6->Location = System::Drawing::Point(363, 198);
this->textBox6->Name = L"textBox6";
this->textBox6->Size = System::Drawing::Size(100, 20);
this->textBox6->TabIndex = 13;
//
// button1
//
this->button1->Location = System::Drawing::Point(363, 247);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 14;
this->button1->Text = L"применить";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm1::button1_Click);
//
// MyForm1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(606, 290);
this->Controls->Add(this->button1);
this->Controls->Add(this->textBox6);
this->Controls->Add(this->textBox5);
this->Controls->Add(this->textBox4);
this->Controls->Add(this->textBox3);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->label7);
this->Controls->Add(this->label6);
this->Controls->Add(this->label5);
this->Controls->Add(this->label4);
this->Controls->Add(this->label3);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Name = L"MyForm1";
this->Text = L"Фильтр 2";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
}
};
}