Справочник функций

Ваш аккаунт

Войти через: 
Забыли пароль?
Регистрация
Информацию о новых материалах можно получать и без регистрации:

Почтовая рассылка

Подписчиков: -1
Последний выпуск: 19.06.2015

2 формы

70K
30 апреля 2011 года
cppn00b
1 / / 30.04.2011
Помогите пожалуйста, где ошибка

123.cpp:
Код:
// 123.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"
#include "Form2.h"


using namespace My123;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
    // Enabling Windows XP visual effects before any controls are created
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);

    // Create the main window and run it
    Application::Run(gcnew Form1());
    return 0;
}


Form1.h:
Код:
#pragma once
#include "Form2.h"
namespace My123 {

    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>
    /// Summary for Form1
    /// </summary>
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~Form1()
        {
            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(58, 68);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(161, 127);
            this->button1->TabIndex = 0;
            this->button1->Text = L"button1";
            this->button1->UseVisualStyleBackColor = true;
            this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
            //
            // Form1
            //
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(292, 273);
            this->Controls->Add(this->button1);
            this->Name = L"Form1";
            this->Text = L"Form1";
            this->ResumeLayout(false);

        }
#pragma endregion
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                 Form2 ^f2 = gcnew Form2();
                 f2->Show();
             }
    };
}


Form2.h:
Код:
#pragma once
#include "Form1.h"
namespace My123 {

    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>
    /// 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(42, 56);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(179, 117);
            this->button1->TabIndex = 0;
            this->button1->Text = L"button1";
            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(292, 273);
            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 ^f1 = gcnew Form1();
                 f1->Show();
             }
    };
}

Цитата:

Ошибка при компиляции:
1>------ Build started: Project: 123, Configuration: Debug Win32 ------
1> 123.cpp
1>c:\documents and settings\asty\desktop\123\123\Form2.h(79): error C2065: 'Form1' : undeclared identifier
1>c:\documents and settings\asty\desktop\123\123\Form2.h(79): error C2065: 'f1' : undeclared identifier
1>c:\documents and settings\asty\desktop\123\123\Form2.h(79): error C2061: syntax error : identifier 'Form1'
1>c:\documents and settings\asty\desktop\123\123\Form2.h(80): error C2065: 'f1' : undeclared identifier
1>c:\documents and settings\asty\desktop\123\123\Form2.h(80): error C2227: left of '->Show' must point to class/struct/union/generic type
1> type is ''unknown-type''
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========




Если в 123.cpp поменять местами:
#include "Form2.h"
#include "Form1.h"
При компиляции получаю

Цитата:

Ошибка при компиляции:
1>------ Build started: Project: 123, Configuration: Debug Win32 ------
1> 123.cpp
1>c:\documents and settings\asty\desktop\123\123\Form1.h(79): error C2065: 'Form2' : undeclared identifier
1>c:\documents and settings\asty\desktop\123\123\Form1.h(79): error C2065: 'f2' : undeclared identifier
1>c:\documents and settings\asty\desktop\123\123\Form1.h(79): error C2061: syntax error : identifier 'Form2'
1>c:\documents and settings\asty\desktop\123\123\Form1.h(80): error C2065: 'f2' : undeclared identifier
1>c:\documents and settings\asty\desktop\123\123\Form1.h(80): error C2227: left of '->Show' must point to class/struct/union/generic type
1> type is ''unknown-type''
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

41K
30 апреля 2011 года
m_cPlusPlus
26 / / 15.08.2009
1. переименуй пространство имен в Form2.h и подключчи его 123.cpp
2. как вариант попробуй определение класса Form2 запихнуть в файл Form1.h. в 123.cpp подключай только Form1.h
278
30 апреля 2011 года
Alexander92
1.1K / / 04.08.2008
Вынесите код Form1::button1_Click() и Form2::button1_Click() из .h-файлов в .cpp-файлы. На форуме полно примеров по вашему вопросу.

Form1.h:
Код:
#pragma once
namespace My123 {

    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>
    /// Summary for Form1
    /// </summary>
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~Form1()
        {
            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(58, 68);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(161, 127);
            this->button1->TabIndex = 0;
            this->button1->Text = L"button1";
            this->button1->UseVisualStyleBackColor = true;
            this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
            //
            // Form1
            //
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(292, 273);
            this->Controls->Add(this->button1);
            this->Name = L"Form1";
            this->Text = L"Form1";
            this->ResumeLayout(false);

        }
#pragma endregion
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) ;

    };
}


123.cpp:
Код:
// 123.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"
#include "Form2.h"

using namespace My123;

System::Void Form1::button1_Click(System::Object^  sender, System::EventArgs^  e)  {
     Form2 ^f2 = gcnew Form2();
     f2->Show();
}


[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
    // Enabling Windows XP visual effects before any controls are created
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);

    // Create the main window and run it
    Application::Run(gcnew Form1());
    return 0;
}


Form2.h:
Код:
#pragma once
namespace My123 {

    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>
    /// 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(42, 56);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(179, 117);
            this->button1->TabIndex = 0;
            this->button1->Text = L"button1";
            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(292, 273);
            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);

    };
}


Form2.cpp:
 
Код:
#include "stdafx.h"
#include "Form1.h"
#include "Form2.h"

using namespace My123;

System::Void Form2::button1_Click(System::Object^  sender, System::EventArgs^  e) {
     Form1 ^f1 = gcnew Form1();
     f1->Show();
}
Реклама на сайте | Обмен ссылками | Ссылки | Экспорт (RSS) | Контакты
Добавить статью | Добавить исходник | Добавить хостинг-провайдера | Добавить сайт в каталог