here is the code:
#pragma once
namespace HelloWorld {
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 for Form1
///
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
///
/// Clean up any resources being used.
///
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
protected:
private:
///
/// Required designer variable.
///
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
void InitializeComponent(void)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(77, 84);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(100, 36);
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) {
MessageBox.Show("Hello World"); //line 79
}
};
}
I would appreciate any help.
VulpesPosted Feb 29, 2012, 4:44 PM
When using C++/CLI, you need to use :: to separate the class name from the method name in the case of a static method.
This is a killer for folks used to C# where the dot separator is used for static methods :)
Sam HobbsPosted Mar 1, 2012, 9:25 AM
For one thing, you need to learn .Net (which for C++ is usually called CLI). It might help to start with a console program. Create a managed C++ console program; that is more appropriate for a "Hello World" program.
Also look at my Managed C++ Wrapper For Unmanaged Code. It shows creation of a Class Library but it might help you.
For your Windows Forms program, it takes time to learn the structure of the programs because a form is relatively complex. If you have done any MFC programming then you know that, except for console and dialog MFC applications, it takes time to learn about the structure of MFC programs.
Another thing about managed C++ programs is that the designers of CLI / .Net do not like to separate classes into headers (.h) and implementation (.cpp) files so CLI / .Net is designed in a manner that is inconsistent with the way that C++ programmers are accustomed to. I won't explain the details here but it will take time for you to learn about that.
imePosted Mar 1, 2012, 6:51 AM
VulpesPosted Mar 1, 2012, 6:39 AM
imePosted Mar 1, 2012, 6:32 AM
Sam HobbsPosted Mar 1, 2012, 5:23 AM
imePosted Feb 29, 2012, 3:33 PM