Untitled
beq
c_cpp
2 years ago
6.4 kB
6
Indexable
// MyForm.cpp
#include "MyForm.h"
using namespace System;
using namespace System::Windows::Forms;
[STAThread]
int main(array<String^>^ args) {
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
test::MyForm form;
Application::Run(% form);
}
// MyForm.h
#pragma once
#include "Test.h"
namespace test {
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>
/// Сводка для MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: добавьте код конструктора
//
}
protected:
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::TextBox^ textBox2;
protected:
private:
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
void InitializeComponent(void)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(54, 177);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(166, 53);
this->button1->TabIndex = 0;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(54, 73);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(166, 20);
this->textBox2->TabIndex = 1;
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 261);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->button1);
this->Name = L"MyForm";
this->Text = L"MyForm";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Test^ test = gcnew Test(); // Создаем экземпляр Form2
// Открываем вторую форму
Test^ testForm = gcnew Test();
if (testForm->ShowDialog() == System::Windows::Forms::DialogResult::OK) {
// Получаем значение из второй формы и выводим на первой форме
textBox2->Text = testForm->GetNumber().ToString();
}
}
};
}
// Test.h
#pragma once
namespace test {
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>
/// Сводка для Test
/// </summary>
public ref class Test : public System::Windows::Forms::Form
{
public:
Test(void)
{
InitializeComponent();
//
//TODO: добавьте код конструктора
//
}
protected:
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
~Test()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::NumericUpDown^ NUM;
protected:
protected:
private:
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
void InitializeComponent(void)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->NUM = (gcnew System::Windows::Forms::NumericUpDown());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->NUM))->BeginInit();
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(54, 193);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(151, 23);
this->button1->TabIndex = 1;
this->button1->Text = L"Ok";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Test::button1_Click);
//
// NUM
//
this->NUM->Location = System::Drawing::Point(54, 91);
this->NUM->Name = L"NUM";
this->NUM->Size = System::Drawing::Size(151, 20);
this->NUM->TabIndex = 2;
//
// Test
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 261);
this->Controls->Add(this->NUM);
this->Controls->Add(this->button1);
this->Name = L"Test";
this->Text = L"Test";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->NUM))->EndInit();
this->ResumeLayout(false);
}
#pragma endregion
public:
int GetNumber() {
// Возвращаем число, введенное пользователем
int test = Convert::ToInt32(NUM->Value);
return test;
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
// Закрываем вторую форму при нажатии на кнопку
this->DialogResult = System::Windows::Forms::DialogResult::OK;
this->Close();
}
};
}
Editor is loading...
Leave a Comment