J
jerrylinkinpark
Guest
Hallo, I have a qestion regarding multi windows programming. My target is to have a main form, showing different steps.
And, when I click step1 button, form2 shows. (Now the step 2 button is disabled)
After having some inputs, when click a button in Form2, I would like to have a function close the form2 and enable the step2 button in Form1. But now it is not possible. I think the problem is that C++ cannot find the the form1 in the header file of form2?
//Form2.h
#pragma once
namespace test {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System:ata;
using namespace System:rawing;
/// <summary>
/// Summary for MyForm2
/// </summary>
public ref class MyForm2 : public System::Windows::Forms::Form
{
public:
MyForm2(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~MyForm2()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
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)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System:rawing:oint(211, 163);
this->button1->Name = L"button1";
this->button1->Size = System:rawing::Size(95, 36);
this->button1->TabIndex = 0;
this->button1->Text = L"Done";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm2::button1_Click);
//
// MyForm2
//
this->AutoScaleDimensions = System:rawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System:rawing::Size(328, 224);
this->Controls->Add(this->button1);
this->Name = L"MyForm2";
this->Text = L"MyForm2";
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Close();
// I tried here different way, but it is not possible..
}
};
}
//Myform1.h
#pragma once
namespace test {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System:ata;
using namespace System:rawing;
/// <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::Button^ button1;
protected:
private: System::Windows::Forms::Button^ button2;
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)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System:rawing:oint(128, 98);
this->button1->Name = L"button1";
this->button1->Size = System:rawing::Size(90, 42);
this->button1->TabIndex = 0;
this->button1->Text = L"step1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm1::button1_Click);
//
// button2
//
this->button2->Enabled = false;
this->button2->Location = System:rawing:oint(264, 98);
this->button2->Name = L"button2";
this->button2->Size = System:rawing::Size(90, 42);
this->button2->TabIndex = 1;
this->button2->Text = L"step2";
this->button2->UseVisualStyleBackColor = true;
//
// MyForm1
//
this->AutoScaleDimensions = System:rawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System:rawing::Size(481, 256);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Name = L"MyForm1";
this->Text = L"MyForm1";
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Hide();
MyForm2 ^ form = gcnew MyForm2; //Here is possible to call MyForm2
form->Show();
}
};
}
//Myform1.cpp
#include "MyForm2.h"
#include "MyForm1.h"
using namespace System;
using namespace System::Windows::Forms;
[STAThreadAttribute]
int main(array<String^>^ args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Application::Run(gcnew test::MyForm1);
return 0;
}
Can anyone help me? Thanks in Advance!
Continue reading...
And, when I click step1 button, form2 shows. (Now the step 2 button is disabled)
After having some inputs, when click a button in Form2, I would like to have a function close the form2 and enable the step2 button in Form1. But now it is not possible. I think the problem is that C++ cannot find the the form1 in the header file of form2?
//Form2.h
#pragma once
namespace test {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System:ata;
using namespace System:rawing;
/// <summary>
/// Summary for MyForm2
/// </summary>
public ref class MyForm2 : public System::Windows::Forms::Form
{
public:
MyForm2(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~MyForm2()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
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)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System:rawing:oint(211, 163);
this->button1->Name = L"button1";
this->button1->Size = System:rawing::Size(95, 36);
this->button1->TabIndex = 0;
this->button1->Text = L"Done";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm2::button1_Click);
//
// MyForm2
//
this->AutoScaleDimensions = System:rawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System:rawing::Size(328, 224);
this->Controls->Add(this->button1);
this->Name = L"MyForm2";
this->Text = L"MyForm2";
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Close();
// I tried here different way, but it is not possible..
}
};
}
//Myform1.h
#pragma once
namespace test {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System:ata;
using namespace System:rawing;
/// <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::Button^ button1;
protected:
private: System::Windows::Forms::Button^ button2;
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)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System:rawing:oint(128, 98);
this->button1->Name = L"button1";
this->button1->Size = System:rawing::Size(90, 42);
this->button1->TabIndex = 0;
this->button1->Text = L"step1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm1::button1_Click);
//
// button2
//
this->button2->Enabled = false;
this->button2->Location = System:rawing:oint(264, 98);
this->button2->Name = L"button2";
this->button2->Size = System:rawing::Size(90, 42);
this->button2->TabIndex = 1;
this->button2->Text = L"step2";
this->button2->UseVisualStyleBackColor = true;
//
// MyForm1
//
this->AutoScaleDimensions = System:rawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System:rawing::Size(481, 256);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Name = L"MyForm1";
this->Text = L"MyForm1";
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Hide();
MyForm2 ^ form = gcnew MyForm2; //Here is possible to call MyForm2
form->Show();
}
};
}
//Myform1.cpp
#include "MyForm2.h"
#include "MyForm1.h"
using namespace System;
using namespace System::Windows::Forms;
[STAThreadAttribute]
int main(array<String^>^ args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Application::Run(gcnew test::MyForm1);
return 0;
}
Can anyone help me? Thanks in Advance!
Continue reading...