zorigt
August 31st, 2003, 10:24 PM
I am new to .NET. I created User Control using managed c++ and
added it into .NET Toolbox. But my control doesn't work. When I put this control on a form, the message box with following error message prompts: " Exception from HRESULT: 0x80131019"
How can I solve this problem. Why does this error ocurr?
// MyControl.h
#pragma once
#using "System.Windows.Forms.dll"
#using "System.dll"
#using "System.Drawing.dll"
using namespace System;
namespace MyControl
{
public __gc class MMyControl: public System::Windows::Forms::UserControl
{
System::Windows::Forms::Button* button1;
System::Windows::Forms::Label* label1;
System::Windows::Forms::TextBox* textBox1;
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container* components;
void InitializeComponent();
public:
MMyControl()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitForm call
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected:
virtual void Dispose( bool disposing );
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
};
}
// MyControl.cpp
// This is the main DLL file.
#include "stdafx.h"
#include "MyControl.h"
void MyControl::MMyControl::Dispose( bool disposing )
{
if( disposing )
{
if( components != NULL )
components->Dispose();
}
System::Windows::Forms::UserControl::Dispose( disposing );
}
void MyControl::MMyControl::InitializeComponent()
{
button1 = new System::Windows::Forms::Button();
label1 = new System::Windows::Forms::Label();
textBox1 = new System::Windows::Forms::TextBox();
SuspendLayout();
//
// button1
//
button1->Location = System::Drawing::Point(40, 96);
button1->Name = "button1";
button1->TabIndex = 0;
button1->Text = "button1";
//
// label1
//
label1->Location = System::Drawing::Point(24, 16);
label1->Name = "label1";
label1->TabIndex = 1;
label1->Text = "label1";
//
// textBox1
//
textBox1->Location = System::Drawing::Point(40, 56);
textBox1->Name = "textBox1";
textBox1->Size = System::Drawing::Size(56, 20);
textBox1->TabIndex = 2;
textBox1->Text = "textBox1";
//
// UserControl1
//
System::Windows::Forms::Control __gc* arrCtls [] = {
textBox1,
label1,
button1};
Controls->AddRange(arrCtls);
Name = "UserControl1";
ResumeLayout(false);
}
I attcahed my contol's source file.[CODE]
added it into .NET Toolbox. But my control doesn't work. When I put this control on a form, the message box with following error message prompts: " Exception from HRESULT: 0x80131019"
How can I solve this problem. Why does this error ocurr?
// MyControl.h
#pragma once
#using "System.Windows.Forms.dll"
#using "System.dll"
#using "System.Drawing.dll"
using namespace System;
namespace MyControl
{
public __gc class MMyControl: public System::Windows::Forms::UserControl
{
System::Windows::Forms::Button* button1;
System::Windows::Forms::Label* label1;
System::Windows::Forms::TextBox* textBox1;
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container* components;
void InitializeComponent();
public:
MMyControl()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitForm call
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected:
virtual void Dispose( bool disposing );
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
};
}
// MyControl.cpp
// This is the main DLL file.
#include "stdafx.h"
#include "MyControl.h"
void MyControl::MMyControl::Dispose( bool disposing )
{
if( disposing )
{
if( components != NULL )
components->Dispose();
}
System::Windows::Forms::UserControl::Dispose( disposing );
}
void MyControl::MMyControl::InitializeComponent()
{
button1 = new System::Windows::Forms::Button();
label1 = new System::Windows::Forms::Label();
textBox1 = new System::Windows::Forms::TextBox();
SuspendLayout();
//
// button1
//
button1->Location = System::Drawing::Point(40, 96);
button1->Name = "button1";
button1->TabIndex = 0;
button1->Text = "button1";
//
// label1
//
label1->Location = System::Drawing::Point(24, 16);
label1->Name = "label1";
label1->TabIndex = 1;
label1->Text = "label1";
//
// textBox1
//
textBox1->Location = System::Drawing::Point(40, 56);
textBox1->Name = "textBox1";
textBox1->Size = System::Drawing::Size(56, 20);
textBox1->TabIndex = 2;
textBox1->Text = "textBox1";
//
// UserControl1
//
System::Windows::Forms::Control __gc* arrCtls [] = {
textBox1,
label1,
button1};
Controls->AddRange(arrCtls);
Name = "UserControl1";
ResumeLayout(false);
}
I attcahed my contol's source file.[CODE]