メニューのオプションを押した後(つまり、子フォームを開くため)、Form1(親)のtextBox1の値をForm2(子)のtextBox2に表示する必要があります。基本的に親子のコミュニケーションの問題。私はこれを変更して必要なことを実行しようとしましたが、運が悪かったのです。
Used_values.h(30) : warning C4101: 'HERE' : unreferenced local variable
Used_values.h(560) : error C2065: 'HERE' : undeclared identifier
ここに私のコードの関連部分を見つけることができます:
Form1(親):
#pragma once
#include "Used_values.h"
namespace Vp_vs_gasconcentration_WindowsForm {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::MenuStrip^ menuStrip1_generalMenu;
private: System::Windows::Forms::ToolStripMenuItem^ usedValues_ToolStripMenuItem;
private: System::Windows::Forms::TextBox^ textBox1_waterDepth;
//(more code...)
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
//(more code...)
this->textBox1_waterDepth = (gcnew System::Windows::Forms::TextBox());
//(more code...)
//
// textBox1_waterDepth
//
this->textBox1_waterDepth->Font = (gcnew System::Drawing::Font(L"Segoe UI", 10));
this->textBox1_waterDepth->Location = System::Drawing::Point(336, 185);
this->textBox1_waterDepth->Name = L"textBox1_waterDepth";
this->textBox1_waterDepth->Size = System::Drawing::Size(100, 25);
this->textBox1_waterDepth->TabIndex = 1;
this->textBox1_waterDepth->Text = L"2170";
this->textBox1_waterDepth->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
this->textBox1_waterDepth->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_waterDepth_TextChanged);
//(more code...)
}
#pragma endregion
//(more code...)
private: System::Void usedValues_ToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
Used_values^ used_values = gcnew Used_values();
used_values->StartPosition = FormStartPosition::CenterParent;
used_values->ShowDialog();
used_values->HERE = textBox1_waterDepth->Text;
}
//(more code...)
};
}
Used_values(子):
#pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
namespace Vp_vs_gasconcentration_WindowsForm {
public ref class Used_values : public System::Windows::Forms::Form
{
public:
Used_values(void)
{
InitializeComponent();
String ^HERE;
}
protected:
~Used_values()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TextBox^ textBox1_waterDepthUsedValues;
//(more code...)
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
//(more code...)
this->textBox1_waterDepthUsedValues = (gcnew System::Windows::Forms::TextBox());
(more code...)
//
// textBox1_waterDepthUsedValues
//
this->textBox1_waterDepthUsedValues->Location = System::Drawing::Point(435, 10);
this->textBox1_waterDepthUsedValues->Name = L"textBox1_waterDepthUsedValues";
this->textBox1_waterDepthUsedValues->Size = System::Drawing::Size(100, 25);
this->textBox1_waterDepthUsedValues->TabIndex = 1;
this->textBox1_waterDepthUsedValues->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
this->textBox1_waterDepthUsedValues->TextChanged += gcnew System::EventHandler(this, &Used_values::textBox1_waterDepthUsedValues_TextChanged);
//(more code...)
}
#pragma endregion
private: System::Void textBox1_waterDepthUsedValues_TextChanged(System::Object^ sender, System::EventArgs^ e) {
textBox1_waterDepthUsedValues->Text = HERE;
}
};
}
したがって、Form2のtextBox(Used_values)に表示されるのは2170(Form1のtextBoxのデフォルト値)です。