Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi everyone!

I would like to know how to show my Form21 from a click on a button in Form1 I used this code here:
C++
#include "Form21.h"
///
Form21 ^maForm2 = gcnew Form21();
maForm21->Show();


I do not know why it does not work yet I found it inhttp://dotnet.developpez.com/faq/cppcli/?page=WinForms#newwinform[^]

it shows me these errors:

C++
1>c:\visual studio 2010\projects\interfaceproject\interfaceproject\Form1.h(526): error C2065: 'Form21' : identificateur non déclaré
1>c:\visual studio 2010\projects\interfaceproject\interfaceproject\Form1.h(526): error C2065: 'maForm2' : identificateur non déclaré
1>c:\visual studio 2010\projects\interfaceproject\interfaceproject\Form1.h(526): error C2061: erreur de syntaxe : identificateur 'Form21'
1>c:\visual studio 2010\projects\interfaceproject\interfaceproject\Form1.h(527): error C2065: 'maForm2' : identificateur non déclaré
1>c:\visual studio 2010\projects\interfaceproject\interfaceproject\Form1.h(527): error C2227: la partie gauche de '->Show' doit pointer vers un type class/struct/union/générique
1>          le type est ''unknown-type''
========== Génération : 0 a réussi, 1 a échoué, 1 mis à jour, 0 a été ignoré 


Thank you so much in advance for helping me
Posted
Comments
Sergey Alexandrovich Kryukov 23-Aug-13 23:13pm    
How can we know what's in "Form21.h"?
—SA
Manel1989 24-Aug-13 5:19am    
this is my Form21.h :
#pragma once
#include "Form1.h"
#include <vector>
#include <string>

namespace interfaceProject {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

///
/// Description résumée de Form2
///

public ref class Form2 : public System::Windows::Forms::Form
{
public:
Form2()
: Form()
{
InitializeComponent();
//
//TODO: ajoutez ici le code du constructeur
//
}

protected:
///
/// Nettoyage des ressources utilisées.
///

~Form2()
{
if (components)
{
delete components;
}
}

private: System::Windows::Forms::DataGridView^ dataGridView1;
protected:

private:
///
/// Variable nécessaire au concepteur.
///

System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
///
/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
///

void InitializeComponent(void)
{
this->dataGridView1 = (gcnew System::Windows::Forms::DataGridView());
(cli::safe_cast<system::componentmodel::isupportinitialize^>(this->dataGridView1))->BeginInit();
this->SuspendLayout();
//
// dataGridView1
//
this->dataGridView1->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
this->dataGridView1->Location = System::Drawing::Point(12, 12);
this->dataGridView1->Name = L"dataGridView1";
this->dataGridView1->Size = System::Drawing::Size(524, 150);
this->dataGridView1->TabIndex = 1;
this->dataGridView1->CellContentClick += gcnew System::Windows::Forms::DataGridViewCellEventHandler(this, &Form2::dataGridView1_CellContentClick);
//
// Form2
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(566, 262);
this->Controls->Add(this->dataGridView1);
this->Name = L"Form2";
this->Text = L"Form2";
(cli::safe_cast<system::componentmodel::isupportinitialize^>(this->dataGridView1))->EndInit();
this->ResumeLayout(false);

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

}
private: System::Void dataGridView1_CellContentClick(System::Object^ sender, System::Windows::Forms::DataGridViewCellEventArgs^ e) {
dataGridView1->AutoResizeColumnHeadersHeight();

// Resize all the row heights to fit the contents of all non-header cells.
dataGridView1->AutoResizeRows(
DataGridViewAutoSizeRowsMode::AllCellsExceptHeaders);
// Set the column header names.

// Create an unbound DataGridView by declaring a column count.
dataGridView1->ColumnCount = 4;
dataGridView1->ColumnHeadersVisible = true;

// Set the column header style.
DataGridViewCellStyle ^ columnHeaderStyle = gcnew DataGridViewCellStyle;
columnHeaderStyle->BackColor = Color::Aqua;
columnHeaderStyle->Font = gcnew System::Drawing::Font( "Verdana",10,FontStyle::Bold );
dataGridView1->ColumnHeadersDefaultCellStyle = columnHeaderStyle;

// Set the column header names.
dataGridView1->Columns[ 0 ]->Name = "Recipe";
dataGridView1->Columns[ 1 ]->Name = "Category";
dataGridView1->Columns[ 2 ]->Name = "Main Ingredients";
dataGridView1->Columns[ 3 ]->Name = "Rating";

// Populate the rows.
array<string^>^row1 = gcnew array<string^>{
"Meatloaf","Main Dish","ground beef","**"
};
array<string^>^row2 = gcnew array<string^>{
"Key Lime Pie","Dessert","lime juice, evaporated milk","****"
};
array<string^>^row3 = gcnew array<string^>{
"Orange-Salsa
Manel1989 24-Aug-13 5:33am    
thank you i found the solution:) have a nice day
Sergey Alexandrovich Kryukov 25-Aug-13 14:44pm    
Congratulations. Next time, please put all code samples to the body of the question where you can format it properly, using "Improve question".
—SA
Richard MacCutchan 24-Aug-13 4:40am    
The errors are quite clear (even with my poor knowledge of French). The header file Form1.h does not contain the include for Form21.h or the Form21.h header does not contain the proper definitions. Look at your source files and check what is defined and whether it is in the correct place.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900