I am using visual studio 2010. I have two windows form that calls each other. Form1 has include Form2
i read that i can not include Form1 in Form2 again. but instead use ref class Form1.
but i am getting the following error
c:\users\seuntech\documents\visual studio 2010\projects\spl_project\spl_project\Form2.h(85): error C2512: 'spl_project::Form1' : no appropriate default constructor available 1>c:\users\seuntech\documents\visual studio 2010\projects\spl_project\spl_project\Form2.h(86): error C2027: use of undefined type 'spl_project::Form1' 1>
c:\users\seuntech\documents\visual studio 2010\projects\spl_project\spl_project\Form2.h(11) : see declaration of 'spl_project::Form1' 1>c:\users\seuntech\documents\visual studio 2010\projects\spl_project\spl_project\Form2.h(86): error C2227: left of '->Show' must point to class/struct/union/generic type 1> spl_project.cpp 1>c:\users\seuntech\documents\visual studio 2010\projects\spl_project\spl_project\Form2.h(85): error C2512: 'spl_project::Form1' : no appropriate default constructor available 1>c:\users\seuntech\documents\visual studio 2010\projects\spl_project\spl_project\Form2.h(86): error C2027: use of undefined type 'spl_project::Form1' 1>
c:\users\seuntech\documents\visual studio 2010\projects\spl_project\spl_project\Form2.h(11) : see declaration of 'spl_project::Form1' 1>c:\users\seuntech\documents\visual studio 2010\projects\spl_project\spl_project\Form2.h(86): error C2227: left of '->Show' must point to class/struct/union/generic type
Code is below
#pragma once
namespace spl_project {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
ref class Form1;
//
/// <summary>
/// Summary for Form2
/// </summary>
public ref class Form2 : public System::Windows::Forms::Form
{
public:
Form2(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form2()
{
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::Drawing::Point(176, 205);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"button2";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form2::button1_Click);
//
// Form2
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 262);
this->Controls->Add(this->button1);
this->Name = L"Form2";
this->Text = L"Form2";
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Form1 ^ na2 = gcnew Form1();
na2->Show();
}
};
}