Je viens d'essayer mais malheureusement ça ne fonctionne pas... je ne sais pas si c'est le code "managed" qui fait ça dans C++ .NET
Voici mom fichier class Form1.h
Code :
#pragma once
namespace test
{
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 __gc class controle;
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public __gc class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//unControle = new controle();
}
protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container * components;
private: System::Windows::Forms::CheckBox * checkBox1;
controle *unControle;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->checkBox1 = new System::Windows::Forms::CheckBox();
this->SuspendLayout();
//
// checkBox1
//
this->checkBox1->Location = System::Drawing::Point(176, 176);
this->checkBox1->Name = S"checkBox1";
this->checkBox1->TabIndex = 0;
this->checkBox1->Text = S"checkBox1";
//
// Form1
//
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->ClientSize = System::Drawing::Size(292, 266);
this->Controls->Add(this->checkBox1);
this->Name = S"Form1";
this->Text = S"Form1";
this->Load += new System::EventHandler(this, Form1_Load);
this->ResumeLayout(false);
}
private: System::Void Form1_Load(System::Object * sender, System::EventArgs * e)
{
unControle = new controle(this);
//this->Controls->Add(unControle->textBox1);
//unControle->textBox1->Text = "test";
}
};
}
et ma class controle.h
Code :
#pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Diagnostics;
public __gc class Form1;
namespace test
{
/// <summary>
/// Summary for controle
/// </summary>
public __gc class controle : public System::ComponentModel::Component
{
public:
controle(Form1 *inForm)
{
lForm = inForm;
InitializeComponent();
}
controle(System::ComponentModel::IContainer *container) : components(0)
{
/// <summary>
/// Required for Windows.Forms Class Composition Designer support
/// </summary>
container->Add(this);
InitializeComponent();
}
protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
public: System::Windows::Forms::TextBox * textBox1;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container *components;
Form1 *lForm;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->textBox1 = new System::Windows::Forms::TextBox();
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(17, 17);
this->textBox1->Name = S"textBox1";
this->textBox1->TabIndex = 0;
this->textBox1->Text = S"textBox1";
}
};
}
Avec ce code j'obtiens une erreeur de compilation:
Form1.h(85): error C2512: 'test::controle' : no appropriate default constructor available
unControle = new controle(this);
Merci,